|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "ActiveSocket.h" |
|
17 #include <es_wsms.h> |
|
18 #include "CLWSPPduHandler.h" |
|
19 #include "wapmsgerr.h" |
|
20 #include <wap_sock.h> |
|
21 #include "WapMessageApiAgent.h" |
|
22 #include "WapSwsLog.h" |
|
23 #include "WapMsgUtils.h" |
|
24 |
|
25 using namespace Wap; |
|
26 |
|
27 void CActiveSocket::NewL(RSocketServ& aSocketServ, RPointerArray<CActiveSocket>& aActiveSockets, Wap::TBearer aBearer, TWapMessageType aType, MProgressNotify* aNotify, Wap::TPort aLocalPort, RConnection* aConnection) |
|
28 /** |
|
29 The static new function instanciates corresponding Bearers in terms of the input bearer type. |
|
30 This function is used by Bound Wap APIs which listen the incoming packet to a specific port. |
|
31 @internalComponent |
|
32 @released |
|
33 @since v8.0 |
|
34 @param aSocketServ the shared RSocketServ instance used in the Wap messaging API which owns this bearer |
|
35 @param aActiveSockets the bearer array used in the Wap messaging API which owns the bearer |
|
36 @param aBearer the bearer to listen on (use EAll for all bearers) |
|
37 @param aType the type of the wap message that will received |
|
38 @param aNotify the instance to be notified when a wap message is received |
|
39 @param aLocalPort the port to listen on |
|
40 @param aConnection the shared connection from Wap messaging API client |
|
41 */ |
|
42 { |
|
43 //Instanciate the corresponding |
|
44 switch(aBearer) |
|
45 { |
|
46 case Wap::ESMS7: |
|
47 case Wap::ESMS: |
|
48 case Wap::EWAPSMS7: |
|
49 case Wap::EWAPSMS: |
|
50 { |
|
51 CActiveSocket* me = new(ELeave) CActiveSocketSMS(aSocketServ, aNotify, aBearer, aLocalPort); |
|
52 CleanupStack::PushL(me); |
|
53 me->ConstructL(aType); |
|
54 aActiveSockets.AppendL(me); |
|
55 CleanupStack::Pop(me); |
|
56 break; |
|
57 } |
|
58 case Wap::EIP: |
|
59 { |
|
60 CActiveSocket* me = new(ELeave) CActiveSocketUDP(aSocketServ, aNotify, aBearer, aLocalPort, aConnection); |
|
61 CleanupStack::PushL(me); |
|
62 me->ConstructL(aType); |
|
63 aActiveSockets.AppendL(me); |
|
64 CleanupStack::Pop(me); |
|
65 break; |
|
66 } |
|
67 case Wap::EAll: |
|
68 { |
|
69 CActiveSocket* me = new(ELeave) CActiveSocketUDP(aSocketServ, aNotify, Wap::EIP, aLocalPort, aConnection); |
|
70 CleanupStack::PushL(me); |
|
71 me->ConstructL(aType); |
|
72 CActiveSocket* me1 = new(ELeave) CActiveSocketSMS(aSocketServ, aNotify, Wap::ESMS, aLocalPort); |
|
73 CleanupStack::PushL(me1); |
|
74 me1->ConstructL(aType); |
|
75 aActiveSockets.ReserveL(2); // pre-allocate the memory |
|
76 aActiveSockets.AppendL(me1); |
|
77 CleanupStack::Pop(me1); |
|
78 aActiveSockets.AppendL(me); |
|
79 CleanupStack::Pop(me); |
|
80 break; |
|
81 } |
|
82 default: |
|
83 { |
|
84 LOG(SwsLog::Printf(_L("CActiveSocket::NewL Unknown Bearer Type"));) |
|
85 User::Leave(Wap::EBearerError); |
|
86 } |
|
87 } |
|
88 } |
|
89 |
|
90 void CActiveSocket::NewL(RSocketServ& aSocketServ, RPointerArray<CActiveSocket>& aActiveSockets, Wap::TBearer aBearer, TWapMessageType aType, MProgressNotify* aNotify, const TSockAddr& aRemoteAddr, RConnection* aConnection) |
|
91 /** |
|
92 The static new function instanciates corresponding Bearers in terms of the input bearer type. |
|
93 This function is used by Fully specified Wap APIs which will open a socket with a single, named remote host. |
|
94 @internalComponent |
|
95 @released |
|
96 @since v8.0 |
|
97 @param aSocketServ the shared RSocketServ instance used in the Wap messaging API which owns this bearer |
|
98 @param aActiveSockets the bearer array used in the Wap messaging API which owns the bearer |
|
99 @param aBearer the bearer to listen on (use EAll for all bearers) |
|
100 @param aType the type of the wap message that will received |
|
101 @param aNotify the instance to be notified when a wap message is received |
|
102 @param aRemoteAddr the remote host to be communicate with |
|
103 @param aConnection the shared connection from Wap messaging API client |
|
104 */ |
|
105 { |
|
106 //Instanciate the corresponding |
|
107 switch(aBearer) |
|
108 { |
|
109 case Wap::ESMS7: |
|
110 case Wap::ESMS: |
|
111 case Wap::EWAPSMS7: |
|
112 case Wap::EWAPSMS: |
|
113 { |
|
114 CActiveSocket* me = new(ELeave) CActiveSocketSMS(aSocketServ, aNotify, aBearer, aRemoteAddr); |
|
115 CleanupStack::PushL(me); |
|
116 me->ConstructL(aType); |
|
117 aActiveSockets.AppendL(me); |
|
118 CleanupStack::Pop(me); |
|
119 break; |
|
120 } |
|
121 case Wap::EIP: |
|
122 { |
|
123 CActiveSocket* me = new(ELeave) CActiveSocketUDP(aSocketServ, aNotify, aBearer, aRemoteAddr, aConnection); |
|
124 CleanupStack::PushL(me); |
|
125 me->ConstructL(aType); |
|
126 aActiveSockets.AppendL(me); |
|
127 CleanupStack::Pop(me); |
|
128 break; |
|
129 } |
|
130 case Wap::EAll: |
|
131 { |
|
132 CActiveSocket* me = new(ELeave) CActiveSocketUDP(aSocketServ, aNotify, aBearer, aRemoteAddr, aConnection); |
|
133 CleanupStack::PushL(me); |
|
134 me->ConstructL(aType); |
|
135 CActiveSocket* me1 = new(ELeave) CActiveSocketSMS(aSocketServ, aNotify, aBearer, aRemoteAddr); |
|
136 CleanupStack::PushL(me1); |
|
137 me1->ConstructL(aType); |
|
138 aActiveSockets.ReserveL(2); // pre-allocate the memory |
|
139 aActiveSockets.AppendL(me1); |
|
140 CleanupStack::Pop(me1); |
|
141 aActiveSockets.AppendL(me); |
|
142 CleanupStack::Pop(me); |
|
143 break; |
|
144 } |
|
145 default: |
|
146 { |
|
147 LOG(SwsLog::Printf(_L("CActiveSocket::NewL Unknown Bearer Type"));) |
|
148 User::Leave(Wap::EBearerError); |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 CActiveSocket::CActiveSocket(RSocketServ& aSocketServ, Wap::TBearer aBearerType, MProgressNotify* aNotify, Wap::TPort aLocalPort) |
|
154 :CActive(EPriorityStandard), iLocalAddr(0), iSocketServ(aSocketServ), iBearerType(aBearerType), iLocalPort(aLocalPort), iSocketState(ESocketIdle),iNotify(aNotify), iBuf(0,0), iRxlength(0), iBufCon(0,0) |
|
155 /** |
|
156 Constructor of bearer base class for Bound Wap APIs |
|
157 @internalComponent |
|
158 @released |
|
159 @since v8.0 |
|
160 */ |
|
161 { |
|
162 CActiveScheduler::Add(this); |
|
163 } |
|
164 |
|
165 CActiveSocket::CActiveSocket(RSocketServ& aSocketServ, Wap::TBearer aBearerType, MProgressNotify* aNotify, const TSockAddr& aRemoteAddr, Wap::TPort aLocalPort): CActive(EPriorityStandard), |
|
166 iRemoteAddr(aRemoteAddr), iLocalAddr(0), iSocketServ(aSocketServ), iBearerType(aBearerType), iLocalPort(aLocalPort), iSocketState(ESocketIdle), iNotify(aNotify), iBuf(0,0), iRxlength(0), iBufCon(0,0) |
|
167 /** |
|
168 Constructor of bearer base class for fully specified Wap APIs |
|
169 @internalComponent |
|
170 @released |
|
171 @since v8.0 |
|
172 */ |
|
173 { |
|
174 CActiveScheduler::Add(this); |
|
175 } |
|
176 |
|
177 CActiveSocket::~CActiveSocket() |
|
178 /** |
|
179 Destructor |
|
180 @internalComponent |
|
181 @released |
|
182 @since v8.0 |
|
183 */ |
|
184 { |
|
185 Cancel(); |
|
186 iSocket.Close(); |
|
187 if (iMessageRecord) |
|
188 { |
|
189 delete iMessageRecord; |
|
190 } |
|
191 } |
|
192 |
|
193 void CActiveSocket::ConstructL(TWapMessageType aType) |
|
194 /** |
|
195 Second Phase Constructor |
|
196 @internalComponent |
|
197 @released |
|
198 @param aType the type of Wap message which is received. |
|
199 @since v8.0 |
|
200 */ |
|
201 { |
|
202 iMessageRecord=CWapMessageRecord::NewL(aType); |
|
203 } |
|
204 |
|
205 RSocket& CActiveSocket::Socket() |
|
206 /** |
|
207 To get the RSocket instance ownd by this bearer |
|
208 @internalComponent |
|
209 @released |
|
210 @since v8.0 |
|
211 @returns the reference of the RSocket instance. |
|
212 */ |
|
213 { |
|
214 return iSocket; |
|
215 } |
|
216 |
|
217 Wap::TBearer CActiveSocket::GetBearerType() |
|
218 /** |
|
219 To get the bearer type of this bearer |
|
220 @internalComponent |
|
221 @released |
|
222 @since v8.0 |
|
223 @returns the bearer type |
|
224 */ |
|
225 { |
|
226 return iBearerType; |
|
227 } |
|
228 |
|
229 TSockAddr& CActiveSocket::GetLocalAddress() |
|
230 /** |
|
231 To get the local address of this bearer |
|
232 @internalComponent |
|
233 @released |
|
234 @since v8.0 |
|
235 @returns the lcoal address instance |
|
236 */ |
|
237 { |
|
238 iSocket.LocalName(iLocalAddr); |
|
239 return iLocalAddr; |
|
240 } |
|
241 |
|
242 TSockAddr& CActiveSocket::GetRemoteAddress() |
|
243 /** |
|
244 To get the remote address of the last received packet |
|
245 @internalComponent |
|
246 @released |
|
247 @since v8.0 |
|
248 @returns the remote address instance |
|
249 */ |
|
250 { |
|
251 return iRemoteAddr; |
|
252 } |
|
253 |
|
254 TInt CActiveSocket::GetRemoteAddress(HBufC8*& aAddr) |
|
255 /** |
|
256 To get the remote address of the last received packet |
|
257 @internalComponent |
|
258 @released |
|
259 @since v8.0 |
|
260 @param aAddr the remote host name |
|
261 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
262 */ |
|
263 { |
|
264 TRAPD(err, aAddr=iRemoteAddr.AllocL()) |
|
265 if (err==KErrNone) |
|
266 { |
|
267 Wap::TPort port; |
|
268 TPtr8 des=aAddr->Des(); |
|
269 TRAP(err, CSWSWapMsgUtils::AnalyseAddrL(iRemoteAddr, iBearerType, des, port)) |
|
270 } |
|
271 else |
|
272 { |
|
273 LOG(SwsLog::Printf(_L("CActiveSocketUDP::GetServerAddress: Alloc Memory Err=%d"), err);) |
|
274 } |
|
275 return err; |
|
276 } |
|
277 |
|
278 TInt CActiveSocket::GetLocalPort(Wap::TPort& aLocalPort) |
|
279 /** |
|
280 To get the lcoal port of this bearer |
|
281 @internalComponent |
|
282 @released |
|
283 @since v8.0 |
|
284 @param aLocalPort the local port of this bearer |
|
285 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
286 */ |
|
287 { |
|
288 GetLocalAddress(); |
|
289 aLocalPort=Wap::TPort(iLocalAddr.Port()); |
|
290 return KErrNone; |
|
291 } |
|
292 |
|
293 TUint32 CActiveSocket::GetPduSize() |
|
294 /** |
|
295 To get the received Wdp Pdu length |
|
296 @internalComponent |
|
297 @released |
|
298 @since v8.0 |
|
299 @returns the length of the received Wdp pdu. |
|
300 */ |
|
301 { |
|
302 return iMessageRecord->GetPduSize(); |
|
303 } |
|
304 |
|
305 TWapMessageState CActiveSocket::GetDataState() |
|
306 /** |
|
307 To get the state of the data that is being received |
|
308 @internalComponent |
|
309 @released |
|
310 @since v8.0 |
|
311 @returns the state of the data that is being received |
|
312 */ |
|
313 { |
|
314 return iMessageRecord->GetDataState(); |
|
315 } |
|
316 |
|
317 void CActiveSocket::SetDataState(TWapMessageState aState) |
|
318 /** |
|
319 To set the state of the data that is being received |
|
320 @internalComponent |
|
321 @released |
|
322 @since v8.0 |
|
323 @param aState the state of the data that is being received |
|
324 */ |
|
325 { |
|
326 iMessageRecord->SetDataState(aState); |
|
327 } |
|
328 |
|
329 TInt CActiveSocket::GetPduData(TDes8& aBuffer, TBool& aTruncated) |
|
330 /** |
|
331 To get the received Wdp pdu. |
|
332 @internalComponent |
|
333 @released |
|
334 @since v8.0 |
|
335 @param aBuffer the buffer to read the received WDP pdu |
|
336 @param aTruncated the flag to represent if the data has be truncated or not |
|
337 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
338 */ |
|
339 { |
|
340 return iMessageRecord->GetPduData(aBuffer, aTruncated); |
|
341 } |
|
342 |
|
343 TInt CActiveSocket::GetWspData(TDes8& aWspHeader, TDes8& aWspBody, TUint8& aTransactionId, TWSPStatus& aStatus) |
|
344 /** |
|
345 To get the received Wsp header, body, tranaction ID and Wsp status. |
|
346 @internalComponent |
|
347 @released |
|
348 @since v8.0 |
|
349 @param aWspHeader the buffer to read the received Wsp header |
|
350 @param aWspBody the buffer to read the received Wsp body |
|
351 @param aTransactionId the transaction ID of the received Wsp Message |
|
352 @param aStatus the Wsp status of the received Wsp Message |
|
353 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
354 */ |
|
355 { |
|
356 return iMessageRecord->GetWspData(aWspHeader, aWspBody, aTransactionId, aStatus); |
|
357 } |
|
358 void CActiveSocket::UnpackPduToWspDataL() |
|
359 /** |
|
360 To extract the Wsp header, body, transaction ID and status from the received WDP pdu |
|
361 @internalComponent |
|
362 @released |
|
363 @since v8.0 |
|
364 */ |
|
365 { |
|
366 iMessageRecord->UnpackPduToWspDataL(); |
|
367 } |
|
368 |
|
369 void CActiveSocket::CleanUpData() |
|
370 { |
|
371 TPtr8 zero(0,0); |
|
372 iBuf.Set(zero); |
|
373 iBufCon.Set(zero); |
|
374 iMessageRecord->CleanUpData(); |
|
375 } |
|
376 |
|
377 /** SMS active socket |
|
378 */ |
|
379 CActiveSocketSMS::CActiveSocketSMS(RSocketServ& aSocketServ, MProgressNotify* aNotify, Wap::TBearer aBearer, Wap::TPort aLocalPort) |
|
380 :CActiveSocket(aSocketServ, aBearer, aNotify, aLocalPort) |
|
381 /** |
|
382 Constructor of SMS bearer for Bound Wap APIs |
|
383 @internalComponent |
|
384 @released |
|
385 @since v8.0 |
|
386 */ |
|
387 { |
|
388 } |
|
389 |
|
390 CActiveSocketSMS::CActiveSocketSMS(RSocketServ& aSocketServ, MProgressNotify* aNotify, Wap::TBearer aBearer, const TSockAddr& aRemoteAddr) |
|
391 :CActiveSocket(aSocketServ, aBearer, aNotify, aRemoteAddr, (Wap::TPort)EWapPortUnspecified) |
|
392 /** |
|
393 Constructor of SMS bearer for fully specified Wap APIs |
|
394 @internalComponent |
|
395 @released |
|
396 @since v8.0 |
|
397 */ |
|
398 { |
|
399 } |
|
400 |
|
401 CActiveSocketSMS::~CActiveSocketSMS() |
|
402 /** |
|
403 Destructor of SMS bearer for fully specified Wap APIs |
|
404 @internalComponent |
|
405 @released |
|
406 @since v8.0 |
|
407 */ |
|
408 { |
|
409 } |
|
410 |
|
411 void CActiveSocketSMS::ConstructL(TWapMessageType aType) |
|
412 /** |
|
413 Second Phase Constructor |
|
414 @internalComponent |
|
415 @released |
|
416 @param aType the type of Wap message which is received. |
|
417 @since v8.0 |
|
418 */ |
|
419 { |
|
420 CActiveSocket::ConstructL(aType); |
|
421 User::LeaveIfError(iSocket.Open(iSocketServ, KWAPSMSAddrFamily, KSockDatagram, KWAPSMSDatagramProtocol)); |
|
422 User::LeaveIfError(iSocket.SetOpt(KWapSmsOptionNewStyleClient,KWapSmsOptionLevel, 0)); |
|
423 TWapAddr wapAddr; |
|
424 wapAddr.SetWapPort(TWapPortNumber(iLocalPort)); |
|
425 TInt err=iSocket.Bind(wapAddr); |
|
426 if (err==KErrInUse) |
|
427 { |
|
428 User::Leave(Wap::EPortAlreadyBound); |
|
429 } |
|
430 } |
|
431 |
|
432 TInt CActiveSocketSMS::AwaitRecvDataSize() |
|
433 /** |
|
434 Read the received Wdp pdu length. |
|
435 @internalComponent |
|
436 @released |
|
437 @since v8.0 |
|
438 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
439 */ |
|
440 { |
|
441 TPckgBuf<TUint32>* length=iMessageRecord->GetPduSizeRef(); |
|
442 iSocket.Ioctl(KSOGetLength, iStatus, length, KSolWapProv); |
|
443 iMessageRecord->SetDataState(ERequestingLength); |
|
444 iSocketState=ESocketWaitingForLength; |
|
445 SetActive(); |
|
446 return KErrNone; |
|
447 } |
|
448 |
|
449 TInt CActiveSocketSMS::Receive() |
|
450 /** |
|
451 Read the received Wdp pdu. |
|
452 @internalComponent |
|
453 @released |
|
454 @since v8.0 |
|
455 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
456 */ |
|
457 { |
|
458 TInt err=KErrNone; |
|
459 TRAP(err, iMessageRecord->CreatePduBufferL(EFalse)) |
|
460 if (err!=KErrNone) |
|
461 { |
|
462 return err; |
|
463 } |
|
464 HBufC8*& pdu=iMessageRecord->GetPduPtr(); |
|
465 iBuf.Set(pdu->Des()); |
|
466 iSocket.RecvFrom(iBuf, iRemoteAddr, 0, iStatus); |
|
467 iMessageRecord->SetDataState(ERequestingData); |
|
468 iSocketState=ESocketWaitingForData; |
|
469 SetActive(); |
|
470 return KErrNone; |
|
471 } |
|
472 |
|
473 void CActiveSocketSMS::RunL() |
|
474 /** |
|
475 Overload the CActive virtual methods |
|
476 @internalComponent |
|
477 @released |
|
478 @since v8.0 |
|
479 */ |
|
480 { |
|
481 switch (iSocketState) |
|
482 { |
|
483 case ESocketWaitingForLength: |
|
484 { |
|
485 LOG(SwsLog::Printf(_L("CActiveSocketSMS::RunL() ESocketWaitingForLength"));) |
|
486 iMessageRecord->SetDataState(EPendingLength); |
|
487 iSocketState=ESocketIdle; |
|
488 TWapNotificationInfo info(iBearerType, iStatus.Int()); |
|
489 TWapNotificationInfoBuf infoBuf(info); |
|
490 iNotify->Notification(EPduLengthReceived, infoBuf); |
|
491 break; |
|
492 } |
|
493 case ESocketWaitingForData: |
|
494 { |
|
495 LOG(SwsLog::Printf(_L("CActiveSocketSMS::RunL() ESocketWaitingForData"));) |
|
496 iMessageRecord->SetDataState(EPendingData); |
|
497 iSocketState=ESocketIdle; |
|
498 TWapNotificationInfo info(iBearerType, iStatus.Int()); |
|
499 TWapNotificationInfoBuf infoBuf(info); |
|
500 iNotify->Notification(EPduReceived, infoBuf); |
|
501 iSocket.SetOpt(KWapSmsOptionOKToDeleteMessage,KWapSmsOptionLevel, 0); |
|
502 break; |
|
503 } |
|
504 default: |
|
505 LOG(SwsLog::Printf(_L("CActiveSocketSMS::RunL() Unknown State"));); |
|
506 } |
|
507 } |
|
508 void CActiveSocketSMS::DoCancel() |
|
509 /** |
|
510 Overload the CActive virtual methods |
|
511 @internalComponent |
|
512 @released |
|
513 @since v8.0 |
|
514 */ |
|
515 { |
|
516 switch (iSocketState) |
|
517 { |
|
518 case ESocketWaitingForLength: |
|
519 { |
|
520 iSocket.CancelIoctl(); |
|
521 break; |
|
522 } |
|
523 case ESocketWaitingForData: |
|
524 { |
|
525 iSocket.CancelRecv(); |
|
526 break; |
|
527 } |
|
528 default: |
|
529 LOG(SwsLog::Printf(_L("CActiveSocketSMS::DoCancel() Unknown State"));); |
|
530 } |
|
531 } |
|
532 |
|
533 // |
|
534 // UDP active socket |
|
535 // |
|
536 CActiveSocketUDP::CActiveSocketUDP(RSocketServ& aSocketServ, MProgressNotify* aNotify, Wap::TBearer aBearer, Wap::TPort aLocalPort, RConnection* aConnection) |
|
537 :CActiveSocket(aSocketServ, aBearer, aNotify, aLocalPort),iConnection(aConnection) |
|
538 /** |
|
539 Constructor for Bound Wap APIs |
|
540 @internalComponent |
|
541 @released |
|
542 @since v8.0 |
|
543 */ |
|
544 { |
|
545 } |
|
546 |
|
547 CActiveSocketUDP::CActiveSocketUDP(RSocketServ& aSocketServ, MProgressNotify* aNotify, Wap::TBearer aBearer, const TSockAddr& aRemoteAddr, RConnection* aConnection) |
|
548 :CActiveSocket(aSocketServ, aBearer, aNotify, aRemoteAddr,0), iConnection(aConnection) |
|
549 /** |
|
550 Constructor for FullySpec Wap APIs |
|
551 @internalComponent |
|
552 @released |
|
553 @since v8.0 |
|
554 */ |
|
555 { |
|
556 } |
|
557 |
|
558 void CActiveSocketUDP::ConstructL(TWapMessageType aType) |
|
559 /** |
|
560 Second Phase constructor |
|
561 @internalComponent |
|
562 @released |
|
563 @since v8.0 |
|
564 */ |
|
565 { |
|
566 CActiveSocket::ConstructL(aType); |
|
567 if (!iConnection) |
|
568 { |
|
569 User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp)); |
|
570 } |
|
571 else |
|
572 { |
|
573 User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, *iConnection)); |
|
574 } |
|
575 TInetAddr inetAddr(iLocalPort); |
|
576 TInt err=iSocket.Bind(inetAddr); |
|
577 if (err==KErrInUse) |
|
578 { |
|
579 User::Leave(Wap::EPortAlreadyBound); |
|
580 } |
|
581 } |
|
582 |
|
583 CActiveSocketUDP::~CActiveSocketUDP() |
|
584 /** |
|
585 Destructor |
|
586 @internalComponent |
|
587 @released |
|
588 @since v8.0 |
|
589 */ |
|
590 { |
|
591 } |
|
592 |
|
593 TInt CActiveSocketUDP::AwaitRecvDataSize() |
|
594 /** |
|
595 Wait for Pdu data size |
|
596 @internalComponent |
|
597 @released |
|
598 @since v8.0 |
|
599 */ |
|
600 { |
|
601 iRxlength=0; |
|
602 TRAPD(err, iMessageRecord->CreatePduBufferL(ETrue)) |
|
603 if (err!=KErrNone) |
|
604 { |
|
605 return err; |
|
606 } |
|
607 HBufC8*& pdu=iMessageRecord->GetPduPtr(); |
|
608 iBuf.Set(pdu->Des()); |
|
609 iSocket.RecvFrom(iBuf, iRemoteAddr, 0, iStatus, iRxlength); |
|
610 iMessageRecord->SetDataState(ERequestingLength); |
|
611 iSocketState=ESocketWaitingForLength; |
|
612 SetActive(); |
|
613 return KErrNone; |
|
614 } |
|
615 |
|
616 TInt CActiveSocketUDP::Receive() |
|
617 /** |
|
618 Receive the pdu |
|
619 @internalComponent |
|
620 @released |
|
621 @since v8.0 |
|
622 */ |
|
623 { |
|
624 if(iMessageRecord->GetDataState()==EContinuous) |
|
625 { |
|
626 TRAPD(err, iMessageRecord->CreatePduBufferL(ETrue)) |
|
627 if (err!=KErrNone) |
|
628 { |
|
629 return err; |
|
630 } |
|
631 HBufC8*& pdu=iMessageRecord->GetPduPtr(); |
|
632 iBuf.Set(pdu->Des()); |
|
633 iBuf.SetLength(iBuf.Length()+1); |
|
634 iBufCon.Set(&iBuf[iBuf.Length()-1],0,iBuf.MaxLength()-iBuf.Length()); |
|
635 iBuf.SetLength(iBuf.Length()+iRxlength()-1); |
|
636 iSocket.RecvFrom(iBufCon, iRemoteAddr, KSockReadContinuation, iStatus,iRxlength); |
|
637 iMessageRecord->SetDataState(ERequestingData); |
|
638 iSocketState=ESocketWaitingForData; |
|
639 SetActive(); |
|
640 } |
|
641 else |
|
642 { |
|
643 iMessageRecord->SetDataState(ERequestingData); |
|
644 iSocketState=ESocketWaitingForData; |
|
645 iStatus = KRequestPending; |
|
646 SetActive(); |
|
647 TRequestStatus* reqStatus=&iStatus; |
|
648 User::RequestComplete(reqStatus, KErrNone); |
|
649 } |
|
650 return KErrNone; |
|
651 } |
|
652 |
|
653 void CActiveSocketUDP::RunL() |
|
654 /** |
|
655 RunL() |
|
656 @internalComponent |
|
657 @released |
|
658 @since v8.0 |
|
659 */ |
|
660 { |
|
661 switch (iSocketState) |
|
662 { |
|
663 case ESocketWaitingForLength: |
|
664 { |
|
665 LOG(SwsLog::Printf(_L("CActiveSocketUDP::RunL() ESocketWaitingForLength"));) |
|
666 iMessageRecord->SetPduSize(iBuf.Length()+ iRxlength()); |
|
667 if(iRxlength() > 0) |
|
668 { |
|
669 iMessageRecord->SetDataState(EContinuous); |
|
670 } |
|
671 else |
|
672 { |
|
673 iMessageRecord->SetDataState(EPendingLength); |
|
674 } |
|
675 iSocketState=ESocketIdle; |
|
676 TWapNotificationInfo info(iBearerType, iStatus.Int()); |
|
677 TWapNotificationInfoBuf infoBuf(info); |
|
678 iNotify->Notification(EPduLengthReceived, infoBuf); |
|
679 break; |
|
680 } |
|
681 case ESocketWaitingForData: |
|
682 { |
|
683 LOG(SwsLog::Printf(_L("CActiveSocketUDP::RunL() ESocketWaitingForData"));) |
|
684 iMessageRecord->SetDataState(EPendingData); |
|
685 iSocketState=ESocketIdle; |
|
686 TWapNotificationInfo info(iBearerType, iStatus.Int()); |
|
687 TWapNotificationInfoBuf infoBuf(info); |
|
688 iNotify->Notification(EPduReceived, infoBuf); |
|
689 break; |
|
690 } |
|
691 default: |
|
692 LOG(SwsLog::Printf(_L("CActiveSocketUDP::RunL() Unknown State"));) |
|
693 break; |
|
694 } |
|
695 } |
|
696 |
|
697 void CActiveSocketUDP::DoCancel() |
|
698 /** |
|
699 Cancel the outstanding request on UDP bearer |
|
700 @internalComponent |
|
701 @released |
|
702 @since v8.0 |
|
703 */ |
|
704 { |
|
705 switch (iSocketState) |
|
706 { |
|
707 case ESocketWaitingForLength: |
|
708 { |
|
709 iSocket.CancelRecv(); |
|
710 break; |
|
711 } |
|
712 case ESocketWaitingForData: |
|
713 { |
|
714 break; |
|
715 } |
|
716 default: |
|
717 LOG(SwsLog::Printf(_L("CActiveSocketUDP::DoCancel() Unknown State"));); |
|
718 } |
|
719 } |
|
720 |
|
721 // |
|
722 //CWapMessageRecord |
|
723 // |
|
724 CWapMessageRecord* CWapMessageRecord::NewL(TWapMessageType aType) |
|
725 /** |
|
726 The static funtion to instanciate the Pdu data record |
|
727 @internalComponent |
|
728 @released |
|
729 @since v8.0 |
|
730 @param aType the type of Wap message which is received. |
|
731 @returns the data record instance. |
|
732 */ |
|
733 { |
|
734 CWapMessageRecord* me; |
|
735 if (aType==EWapWsp) |
|
736 { |
|
737 me = new(ELeave) CWspMessageRecord(); |
|
738 } |
|
739 else |
|
740 { |
|
741 me = new(ELeave) CWdpMessageRecord(); |
|
742 } |
|
743 return me; |
|
744 } |
|
745 |
|
746 CWapMessageRecord::CWapMessageRecord() |
|
747 /** |
|
748 Constructor |
|
749 @internalComponent |
|
750 @released |
|
751 @since v8.0 |
|
752 */ |
|
753 { |
|
754 } |
|
755 |
|
756 CWapMessageRecord::~CWapMessageRecord() |
|
757 /** |
|
758 Destructor |
|
759 @internalComponent |
|
760 @released |
|
761 @since v8.0 |
|
762 */ |
|
763 { |
|
764 if (iPdu) |
|
765 { |
|
766 delete iPdu; |
|
767 } |
|
768 } |
|
769 |
|
770 TWapMessageState CWapMessageRecord::GetDataState() |
|
771 /** |
|
772 To get the state of the data that is being received |
|
773 @internalComponent |
|
774 @released |
|
775 @since v8.0 |
|
776 returns the state of the data that is being received |
|
777 */ |
|
778 { |
|
779 return iState; |
|
780 } |
|
781 |
|
782 void CWapMessageRecord::SetDataState(TWapMessageState aState) |
|
783 /** |
|
784 To set the state of the data that is being received |
|
785 @internalComponent |
|
786 @released |
|
787 @since v8.0 |
|
788 @param the state of the data that is being received |
|
789 */ |
|
790 { |
|
791 iState=aState; |
|
792 } |
|
793 |
|
794 TPckgBuf<TUint32>* CWapMessageRecord::GetPduSizeRef() |
|
795 /** |
|
796 To get the buffer which is used to contain the received data length |
|
797 @internalComponent |
|
798 @released |
|
799 @since v8.0 |
|
800 @returns the pointer to the buffer length |
|
801 */ |
|
802 { |
|
803 return &iDataLength; |
|
804 } |
|
805 |
|
806 void CWapMessageRecord::SetPduSize(TUint32 aLength) |
|
807 { |
|
808 iDataLength=aLength; |
|
809 } |
|
810 |
|
811 TUint32 CWapMessageRecord::GetPduSize() |
|
812 /** |
|
813 To get the received wdp pdu length |
|
814 @internalComponent |
|
815 @released |
|
816 @since v8.0 |
|
817 @returns the received wdp pdu length |
|
818 */ |
|
819 { |
|
820 iState=EGotLength; |
|
821 return iDataLength(); |
|
822 } |
|
823 |
|
824 HBufC8*& CWapMessageRecord::GetPduPtr() |
|
825 /** |
|
826 To get the received wdp pdu. |
|
827 @internalComponent |
|
828 @released |
|
829 @since v8.0 |
|
830 @returns the pointer the received wdp buffer |
|
831 */ |
|
832 { |
|
833 return iPdu; |
|
834 } |
|
835 |
|
836 void CWapMessageRecord::CreatePduBufferL(TBool aFixLengthFlag) |
|
837 /** |
|
838 create the wdp pdu buffer according to the length |
|
839 @internalComponent |
|
840 @released |
|
841 @since v8.0 |
|
842 */ |
|
843 { |
|
844 if (iState==EContinuous) |
|
845 { |
|
846 iPdu->ReAllocL(iDataLength()); |
|
847 } |
|
848 else if (!aFixLengthFlag) |
|
849 { |
|
850 iPdu=HBufC8::NewL(iDataLength()); |
|
851 } |
|
852 else |
|
853 { |
|
854 iPdu=HBufC8::NewL(KMaxUdpBearerDataBufferLength); |
|
855 } |
|
856 } |
|
857 |
|
858 void CWapMessageRecord::CleanUpData() |
|
859 /** |
|
860 clean up the receive buffer. |
|
861 @internalComponent |
|
862 @released |
|
863 @since v8.0 |
|
864 */ |
|
865 { |
|
866 if (iPdu) |
|
867 { |
|
868 delete iPdu; |
|
869 iPdu=NULL; |
|
870 } |
|
871 iDataLength.FillZ(); |
|
872 iState=EIdle; |
|
873 } |
|
874 |
|
875 // |
|
876 //CWspMessageRecord methods |
|
877 // |
|
878 CWspMessageRecord::CWspMessageRecord() |
|
879 /** |
|
880 Constructor |
|
881 @internalComponent |
|
882 @released |
|
883 @since v8.0 |
|
884 */ |
|
885 { |
|
886 } |
|
887 |
|
888 CWspMessageRecord::~CWspMessageRecord() |
|
889 /** |
|
890 Destructor |
|
891 @internalComponent |
|
892 @released |
|
893 @since v8.0 |
|
894 */ |
|
895 { |
|
896 if (iWspHeader) |
|
897 { |
|
898 delete iWspHeader; |
|
899 } |
|
900 if (iWspBody) |
|
901 { |
|
902 delete iWspBody; |
|
903 } |
|
904 } |
|
905 |
|
906 void CWspMessageRecord::UnpackPduToWspDataL() |
|
907 /** |
|
908 To unpack the received wdp pdu to wsp message. |
|
909 @internalComponent |
|
910 @released |
|
911 @since v8.0 |
|
912 */ |
|
913 { |
|
914 TWSPPduType type; |
|
915 CCLWSPPduHandler::UnpackWSPPduL(iPdu, type, iWspHeader, iWspBody, iTransactionId, iWspStatus); |
|
916 } |
|
917 |
|
918 TInt CWspMessageRecord::GetWspData(TDes8& aWspHeader, TDes8& aWspBody, TUint8& aTransactionId, TWSPStatus& aWspStatus) |
|
919 /** |
|
920 To read the wsp message from the buffer |
|
921 @internalComponent |
|
922 @released |
|
923 @since v8.0 |
|
924 @param aWspHeader the buffer to contain the wsp header |
|
925 @param aWspBody the buffer to contain the wsp body |
|
926 @param iTransactionId the received transaction ID |
|
927 @param aWspStatus the received wsp status |
|
928 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
929 */ |
|
930 { |
|
931 if (!iWspHeader && !iWspBody) |
|
932 { |
|
933 // if no data, should not be here at all |
|
934 LOG(SwsLog::Printf(_L("CWspMessageRecord::GetWspData() No Data Available"));) |
|
935 CleanUpData(); |
|
936 return KErrBadDescriptor; |
|
937 } |
|
938 TInt ret=KErrNone; |
|
939 //Copy the transaction ID |
|
940 aTransactionId=iTransactionId; |
|
941 aWspStatus=iWspStatus; |
|
942 //Copy the header |
|
943 TInt bufferLength; |
|
944 if (iWspHeader) |
|
945 { |
|
946 bufferLength=aWspHeader.MaxLength(); |
|
947 TPtrC8 remainHeader=iWspHeader->Mid(iHeaderOffset); |
|
948 //Client Header buffer is not long enough |
|
949 if (bufferLength<remainHeader.Length()) |
|
950 { |
|
951 aWspHeader.Copy(remainHeader.Ptr(), bufferLength); |
|
952 iHeaderOffset+=bufferLength; |
|
953 iState=EReading; |
|
954 ret=Wap::EMoreData; |
|
955 } |
|
956 else |
|
957 { |
|
958 aWspHeader.Copy(remainHeader); |
|
959 iHeaderOffset=0; |
|
960 delete iWspHeader; |
|
961 iWspHeader=NULL; |
|
962 } |
|
963 } |
|
964 if (iWspBody) |
|
965 { |
|
966 //Copy the Body |
|
967 bufferLength=aWspBody.MaxLength(); |
|
968 TPtrC8 remainBody=iWspBody->Mid(iBodyOffset); |
|
969 |
|
970 //Client Header buffer is not long enough |
|
971 if (bufferLength<remainBody.Length()) |
|
972 { |
|
973 aWspBody.Copy(remainBody.Ptr(), bufferLength); |
|
974 iBodyOffset+=bufferLength; |
|
975 iState=EReading; |
|
976 ret=Wap::EMoreData; |
|
977 } |
|
978 else |
|
979 { |
|
980 aWspBody.Copy(remainBody); |
|
981 iBodyOffset=0; |
|
982 delete iWspBody; |
|
983 iWspBody=NULL; |
|
984 } |
|
985 } |
|
986 //All Wsp Data has been read. |
|
987 if (ret==KErrNone) |
|
988 { |
|
989 delete iPdu; |
|
990 iPdu=NULL; |
|
991 iDataLength.FillZ(); |
|
992 iState=EIdle; |
|
993 } |
|
994 return ret; |
|
995 } |
|
996 |
|
997 TInt CWspMessageRecord::GetPduData(TDes8& /*aBuffer*/, TBool& /*aTruncated*/) |
|
998 /** |
|
999 Not supported |
|
1000 @internalComponent |
|
1001 @released |
|
1002 @since v8.0 |
|
1003 */ |
|
1004 {//Should not be used |
|
1005 return KErrNotSupported; |
|
1006 } |
|
1007 |
|
1008 void CWspMessageRecord::CleanUpData() |
|
1009 /** |
|
1010 To clean up the wsp related data |
|
1011 @internalComponent |
|
1012 @released |
|
1013 @since v8.0 |
|
1014 */ |
|
1015 { |
|
1016 CWapMessageRecord::CleanUpData(); |
|
1017 if (iWspHeader) |
|
1018 { |
|
1019 delete iWspHeader; |
|
1020 iWspHeader=NULL; |
|
1021 } |
|
1022 if (iWspBody) |
|
1023 { |
|
1024 delete iWspBody; |
|
1025 iWspBody=NULL; |
|
1026 } |
|
1027 iTransactionId=0; |
|
1028 iHeaderOffset=0; |
|
1029 iBodyOffset=0; |
|
1030 } |
|
1031 // |
|
1032 //CWspMessageRecord method |
|
1033 // |
|
1034 CWdpMessageRecord::CWdpMessageRecord() |
|
1035 /** |
|
1036 Constructor |
|
1037 @internalComponent |
|
1038 @released |
|
1039 @since v8.0 |
|
1040 */ |
|
1041 { |
|
1042 } |
|
1043 |
|
1044 CWdpMessageRecord::~CWdpMessageRecord() |
|
1045 /** |
|
1046 Destructor |
|
1047 @internalComponent |
|
1048 @released |
|
1049 @since v8.0 |
|
1050 */ |
|
1051 { |
|
1052 } |
|
1053 |
|
1054 TInt CWdpMessageRecord::GetPduData(TDes8& aBuffer, TBool& aTruncated) |
|
1055 /** |
|
1056 To read the received Wdp pdu |
|
1057 @internalComponent |
|
1058 @released |
|
1059 @since v8.0 |
|
1060 @param aBuffer the buffer to contain the received wdp pdu |
|
1061 @param aTruncated the flag to represent if the data is truncated or not |
|
1062 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
1063 */ |
|
1064 { |
|
1065 if (!iPdu) |
|
1066 { |
|
1067 //Should not be here at all |
|
1068 LOG(SwsLog::Printf(_L("CWdpMessageRecord::GetPduData No Data Available"));) |
|
1069 CleanUpData(); |
|
1070 return KErrBadDescriptor; |
|
1071 } |
|
1072 TInt ret=KErrNone; |
|
1073 TInt bufLength=aBuffer.MaxLength(); |
|
1074 TPtrC8 remainPdu=iPdu->Mid(iPduOffset); |
|
1075 if (bufLength<remainPdu.Length()) |
|
1076 { |
|
1077 aBuffer.Copy(remainPdu.Ptr(), bufLength); |
|
1078 iPduOffset+=bufLength; |
|
1079 iState=EReading; |
|
1080 aTruncated=ETrue; |
|
1081 ret=Wap::EMoreData; |
|
1082 } |
|
1083 else |
|
1084 { |
|
1085 aBuffer.Copy(remainPdu); |
|
1086 aTruncated=EFalse; |
|
1087 CleanUpData(); |
|
1088 } |
|
1089 return ret; |
|
1090 } |
|
1091 |
|
1092 void CWdpMessageRecord::UnpackPduToWspDataL() |
|
1093 /** |
|
1094 Not supported |
|
1095 @internalComponent |
|
1096 @released |
|
1097 @since v8.0 |
|
1098 */ |
|
1099 { |
|
1100 //Should not be used |
|
1101 User::Leave(KErrNotSupported); |
|
1102 } |
|
1103 |
|
1104 TInt CWdpMessageRecord::GetWspData(TDes8& /*aWspHeader*/, TDes8& /*aWspBody*/, TUint8& /*aTransactionId*/, TWSPStatus& /*aWspStatus*/) |
|
1105 /** |
|
1106 Not supported |
|
1107 @internalComponent |
|
1108 @released |
|
1109 @since v8.0 |
|
1110 */ |
|
1111 { |
|
1112 //Should not be used |
|
1113 return KErrNotSupported; |
|
1114 } |
|
1115 |
|
1116 void CWdpMessageRecord::CleanUpData() |
|
1117 /** |
|
1118 To clean up the wdp related data |
|
1119 @internalComponent |
|
1120 @released |
|
1121 @since v8.0 |
|
1122 */ |
|
1123 { |
|
1124 CWapMessageRecord::CleanUpData(); |
|
1125 iPduOffset=0; |
|
1126 } |