|
1 // Copyright (c) 2008-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 "WapMessageApiAgent.h" |
|
17 #include "WapMsgUtils.h" |
|
18 #include "CLWSPPduHandler.h" |
|
19 #include <es_wsms.h> |
|
20 #include <wapmsgerr.h> |
|
21 #include "WapSwsLog.h" |
|
22 |
|
23 CWapAsyncCallBack::CWapAsyncCallBack( const TCallBack& aCallBack, TInt aPriority ) |
|
24 : CActive( aPriority ), iCallBack( aCallBack ) |
|
25 { |
|
26 CActiveScheduler::Add( this ); |
|
27 } |
|
28 |
|
29 CWapAsyncCallBack::~CWapAsyncCallBack() |
|
30 { |
|
31 Cancel(); |
|
32 } |
|
33 |
|
34 void CWapAsyncCallBack::CallBack() |
|
35 { |
|
36 if ( !IsActive() ) |
|
37 { |
|
38 TRequestStatus* status = &iStatus; |
|
39 User::RequestComplete( status, KErrNone ); |
|
40 SetActive(); |
|
41 } |
|
42 } |
|
43 |
|
44 void CWapAsyncCallBack::RunL() |
|
45 { |
|
46 iCallBack.CallBack(); |
|
47 } |
|
48 |
|
49 void CWapAsyncCallBack::DoCancel() |
|
50 { |
|
51 // Empty - request already completed in CallBack() |
|
52 } |
|
53 |
|
54 // |
|
55 //CWapMessageApiAgent class Method |
|
56 // |
|
57 CWapMessageApiAgent::CWapMessageApiAgent(TWapMessageType aMessageType):iMessageType(aMessageType) |
|
58 /** |
|
59 Constuctor. |
|
60 @internalComponent |
|
61 @released since v8.0 |
|
62 @param aMessageType the message type that handled by this agent |
|
63 */ |
|
64 { |
|
65 } |
|
66 |
|
67 CWapMessageApiAgent::~CWapMessageApiAgent() |
|
68 /** |
|
69 Destrutor |
|
70 @internalComponent. |
|
71 @released since v8.0 |
|
72 */ |
|
73 { |
|
74 TInt count=iBearers.Count(); |
|
75 for (TInt i=0; i<count; i++) |
|
76 { |
|
77 iBearers[i]->Cancel(); |
|
78 iBearers[i]->CleanUpData(); |
|
79 } |
|
80 iBearers.ResetAndDestroy(); |
|
81 iSocketServ.Close(); |
|
82 if (iTimeoutTimer) |
|
83 { |
|
84 iTimeoutTimer->Cancel(); |
|
85 delete iTimeoutTimer; |
|
86 } |
|
87 if (iAsyncReadCompletion) |
|
88 { |
|
89 delete iAsyncReadCompletion; |
|
90 } |
|
91 } |
|
92 |
|
93 TInt CWapMessageApiAgent::CompleteReading(TAny* aAgent) |
|
94 { |
|
95 CWapMessageApiAgent* agent = reinterpret_cast<CWapMessageApiAgent*>(aAgent); |
|
96 return agent->DoCompleteReading(); |
|
97 } |
|
98 |
|
99 TInt CWapMessageApiAgent::DoCompleteReading() |
|
100 { |
|
101 iRequestActive=EFalse; |
|
102 User::RequestComplete(iRequestStatus, iLastReadingError); |
|
103 return KErrNone; |
|
104 } |
|
105 void CWapMessageApiAgent::ConstructL() |
|
106 /** |
|
107 Second Phase Constructor |
|
108 @internalComponent. |
|
109 @released since v8.0 |
|
110 */ |
|
111 { |
|
112 iTimeoutTimer = CTimeOutTimer::NewL(*this); |
|
113 TCallBack callback = TCallBack(CompleteReading, this); |
|
114 iAsyncReadCompletion = new (ELeave) CWapAsyncCallBack(callback, CActive::EPriorityHigh); |
|
115 User::LeaveIfError(iSocketServ.Connect()); |
|
116 } |
|
117 |
|
118 CActiveSocket* CWapMessageApiAgent::GetActiveSocketByBearer(Wap::TBearer aBearer) |
|
119 /** |
|
120 To Get the CActiveSocket from the Array by Bearer type. |
|
121 @internalComponent. |
|
122 @released since v8.0 |
|
123 @param aBearer (in)the bearer type of the CActiveSocket |
|
124 @returns the pointer of CAtiveSocket |
|
125 */ |
|
126 { |
|
127 TInt count=iBearers.Count(); |
|
128 for (TInt i=0; i<count; i++) |
|
129 { |
|
130 Wap::TBearer bearer=iBearers[i]->GetBearerType(); |
|
131 if (bearer==aBearer) |
|
132 { |
|
133 return iBearers[i]; |
|
134 } |
|
135 else |
|
136 { |
|
137 if ((aBearer>=Wap::ESMS7 && aBearer<=Wap::EWAPSMS) && (bearer>=Wap::ESMS7 && bearer<=Wap::EWAPSMS)) |
|
138 { |
|
139 return iBearers[i]; |
|
140 } |
|
141 } |
|
142 } |
|
143 return NULL; |
|
144 } |
|
145 |
|
146 CActiveSocket* CWapMessageApiAgent::GetActiveSocketByStatus(TWapMessageState aState) |
|
147 /** |
|
148 To Get the CActiveSocket from the Array by Data State. |
|
149 @internalComponent. |
|
150 @released since v8.0 |
|
151 @param aState (in)the Data state of the CActiveSocket |
|
152 @returns the pointer of CAtiveSocket |
|
153 */ |
|
154 { |
|
155 TInt count=iBearers.Count(); |
|
156 for (TInt i=0; i<count; i++) |
|
157 { |
|
158 if (iBearers[i]->GetDataState()==aState) |
|
159 { |
|
160 return iBearers[i]; |
|
161 } |
|
162 } |
|
163 return NULL; |
|
164 } |
|
165 |
|
166 void CWapMessageApiAgent::TimerExpired() |
|
167 /** |
|
168 To handle the receive time out. |
|
169 @internalComponent. |
|
170 @released since v8.0 |
|
171 */ |
|
172 { |
|
173 TInt count=iBearers.Count(); |
|
174 for (TInt i=0; i<count; i++) |
|
175 { |
|
176 iBearers[i]->Cancel(); |
|
177 iBearers[i]->CleanUpData(); |
|
178 } |
|
179 iRequestActive=EFalse; |
|
180 User::RequestComplete(iRequestStatus, KErrTimedOut); |
|
181 } |
|
182 |
|
183 TInt CWapMessageApiAgent::GetLocalPort(Wap::TPort& aLocalPort) |
|
184 /** |
|
185 To Get local port of the last received packet |
|
186 @internalComponent. |
|
187 @released since v8.0 |
|
188 @param aLocalPort (out)the reference of the localPort. |
|
189 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
190 */ |
|
191 { |
|
192 if (!iIsOpen) |
|
193 { |
|
194 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::GetLocalPort: Trying to GetLocalPort on unconnected API."));) |
|
195 return KErrNotReady; |
|
196 } |
|
197 CActiveSocket* sock=GetActiveSocketByBearer(iLastPduBearer); |
|
198 if (!sock) |
|
199 { |
|
200 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::GetLocalPort: Can not find Last Bearer."));) |
|
201 return Wap::EBearerError; |
|
202 } |
|
203 sock->GetLocalPort(aLocalPort); |
|
204 return KErrNone; |
|
205 } |
|
206 |
|
207 TInt CWapMessageApiAgent::GetLocalAddress(HBufC8*& aLocalHost) |
|
208 /** |
|
209 To Get local Address of the last received Packet |
|
210 @internalComponent. |
|
211 @released since v8.0 |
|
212 @param aLocalHost (out)the reference of the localHost. |
|
213 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
214 */ |
|
215 { |
|
216 if (!iIsOpen) |
|
217 { |
|
218 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::GetLocalAddress: Trying to GetLocalAddress on unconnected API."));) |
|
219 return KErrNotReady; |
|
220 } |
|
221 CActiveSocket* sock=GetActiveSocketByBearer(iLastPduBearer); |
|
222 if (!sock) |
|
223 { |
|
224 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::GetLocalAddress: Can not find Last Bearer"));) |
|
225 return Wap::EBearerError; |
|
226 } |
|
227 TSockAddr& localHost=sock->GetLocalAddress(); |
|
228 TInt err=KErrNone; |
|
229 TRAP(err, aLocalHost=localHost.AllocL()) |
|
230 if (err) |
|
231 { |
|
232 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::GetLocalAddress: Alloc Memory Err=%d"), err);) |
|
233 } |
|
234 return err; |
|
235 } |
|
236 |
|
237 TInt CWapMessageApiAgent::GetBearer(Wap::TBearer& aBearer) |
|
238 /** |
|
239 To Get Bearer of the last received packet |
|
240 @internalComponent. |
|
241 @released since v8.0 |
|
242 @param aBearer (out)the reference of the Bearer. |
|
243 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
244 */ |
|
245 { |
|
246 if (!iIsOpen) |
|
247 { |
|
248 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::GetBearer: Trying to GetBearer on unconnected API."));) |
|
249 return KErrNotReady; |
|
250 } |
|
251 aBearer=iLastPduBearer; |
|
252 return KErrNone; |
|
253 } |
|
254 |
|
255 TInt CWapMessageApiAgent::GetServerAddress(HBufC8*& aServerHost) |
|
256 /** |
|
257 To Get Server Host of the last received packet |
|
258 @internalComponent. |
|
259 @released since v8.0 |
|
260 @param aServerHost (out)the reference of the Server Host. |
|
261 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
262 */ |
|
263 { |
|
264 if (!iIsOpen) |
|
265 { |
|
266 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::GetServerAddress: Trying to GetServerAddress on unconnected API."));) |
|
267 return KErrNotReady; |
|
268 } |
|
269 CActiveSocket* sock=GetActiveSocketByBearer(iLastPduBearer); |
|
270 if (!sock) |
|
271 { |
|
272 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::GetServerAddress: Can not find last error."));) |
|
273 return Wap::EBearerError; |
|
274 } |
|
275 return sock->GetRemoteAddress(aServerHost); |
|
276 } |
|
277 |
|
278 void CWapMessageApiAgent::CancelRequest() |
|
279 /** |
|
280 To Cancel the client's request |
|
281 @internalComponent. |
|
282 @released since v8.0 |
|
283 */ |
|
284 { |
|
285 if (iIsOpen) |
|
286 { |
|
287 TInt count=iBearers.Count(); |
|
288 for (TInt i=0; i<count; i++) |
|
289 { |
|
290 iBearers[i]->Cancel(); |
|
291 iBearers[i]->CleanUpData(); |
|
292 } |
|
293 iTimeoutTimer->Cancel(); |
|
294 if (iRequestActive) |
|
295 { |
|
296 iRequestActive=EFalse; |
|
297 iAsyncReadCompletion->Cancel(); |
|
298 User::RequestComplete(iRequestStatus, KErrCancel); |
|
299 } |
|
300 } |
|
301 } |
|
302 |
|
303 TInt CWapMessageApiAgent::Connect(Wap::TBearer aBearer, Wap::TPort aPort, TBool aSecure) |
|
304 /** |
|
305 Opening an endpoint that can be used to listen for subsequent incoming datagrams. |
|
306 @internalComponent. |
|
307 @released since v8.0 |
|
308 @param aBearer (In) the bearer to listen on |
|
309 @param aPort (In) the port to listen on. |
|
310 @param aSecure (In) security flag indicates whether WTLS will be used or not (Not Supported) |
|
311 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
312 */ |
|
313 { |
|
314 TInetAddr inetAddr( KInetAddrAny, 0); |
|
315 return (Connect(aBearer, aPort, aSecure, inetAddr)); |
|
316 } |
|
317 |
|
318 TInt CWapMessageApiAgent::Connect(Wap::TBearer aBearer, Wap::TPort aPort, TBool /*aSecure*/, TInetAddr /*aInetAddr*/) |
|
319 /** |
|
320 Opening an endpoint that can be used to listen for subsequent incoming datagrams. |
|
321 @internalComponent. |
|
322 @released since v8.0 |
|
323 @param aBearer (In) the bearer to listen on |
|
324 @param aPort (In) the port to listen on. |
|
325 @param aSecure (In) security flag indicates whether WTLS will be used or not (Not Supported) |
|
326 @param aInetAddr (In) Not In Use. |
|
327 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
328 */ |
|
329 { |
|
330 TInt ret=KErrNone; |
|
331 if (!iIsOpen) |
|
332 { |
|
333 TRAP(ret, CActiveSocket::NewL(iSocketServ, iBearers, aBearer, iMessageType, this, aPort)) |
|
334 if (ret!=KErrNone) |
|
335 { |
|
336 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect: CActiveSocket Instantiate err=%d."),ret);) |
|
337 return ret; |
|
338 } |
|
339 iIsOpen=ETrue; |
|
340 } |
|
341 else |
|
342 { |
|
343 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect:Trying Connect twice to the API."));) |
|
344 ret=KErrInUse; |
|
345 } |
|
346 return ret; |
|
347 } |
|
348 |
|
349 TInt CWapMessageApiAgent::Connect(Wap::TBearer aBearer, Wap::TPort aPort, TBool /*aSecure*/, TInt aSocketServHandle, RConnection* aConnection) |
|
350 /** |
|
351 Opening an endpoint that can be used to listen for subsequent incoming datagrams. |
|
352 @internalComponent. |
|
353 @released since v8.0 |
|
354 @param aBearer (In) the bearer to listen on |
|
355 @param aPort (In) the port to listen on. |
|
356 @param aSecure (In) security flag indicates whether WTLS will be used or not (Not Supported) |
|
357 @param aSocketServHandle (In) The Socket Server ID. |
|
358 @param aConnection (In) The RConnection that shared with the client. |
|
359 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
360 */ |
|
361 { |
|
362 if (aSocketServHandle==0 || !aConnection) |
|
363 { |
|
364 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect:Parameter Error"));) |
|
365 return KErrArgument; |
|
366 } |
|
367 TInt ret=KErrNone; |
|
368 if (!iIsOpen) |
|
369 { |
|
370 iSocketServ.SetHandle(aSocketServHandle); |
|
371 TRAP(ret, CActiveSocket::NewL(iSocketServ, iBearers, aBearer, iMessageType, this, aPort, aConnection)) |
|
372 if (ret!=KErrNone) |
|
373 { |
|
374 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect: CActiveSocket Instantiate err=%d."), ret);) |
|
375 return ret; |
|
376 } |
|
377 iIsOpen=ETrue; |
|
378 } |
|
379 else |
|
380 { |
|
381 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect:Trying to Connect twice to the API."));) |
|
382 ret=KErrInUse; |
|
383 } |
|
384 return ret; |
|
385 } |
|
386 |
|
387 TInt CWapMessageApiAgent::Connect(const TDesC8& aRemoteHost, Wap::TPort aRemotePort, Wap::TBearer aBearer, TBool /*aSecure*/, TInetAddr /*aInetAddr*/) |
|
388 /** |
|
389 Opens a socket which is to be used only with a single, named remote host. |
|
390 @internalComponent. |
|
391 @released since v8.0 |
|
392 @param aRemoteHost (In) the name of the remote host to connect. |
|
393 @param aRemotePort (In) the port of the remote host to connect. |
|
394 @param aBearer (In) the bearer to be used |
|
395 @param aSecure (In) security flag indicates whether WTLS will be used or not (Not Supported) |
|
396 @param aInetAddr (In) Not In Use |
|
397 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
398 */ |
|
399 { |
|
400 if (aBearer==Wap::EAll) |
|
401 { |
|
402 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::SendWspMessage:Connect to EAll Error"));) |
|
403 return Wap::EBearerError; |
|
404 } |
|
405 TInt ret=KErrNone; |
|
406 if (!iIsOpen) |
|
407 { |
|
408 TSockAddr remoteAddr; |
|
409 TRAP(ret, CSWSWapMsgUtils::BuildAddrL(remoteAddr, aBearer, aRemoteHost, aRemotePort)) |
|
410 if (ret!=KErrNone) |
|
411 { |
|
412 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect: BuildAddress err=%d."), ret);) |
|
413 return ret; |
|
414 } |
|
415 TRAP(ret, CActiveSocket::NewL(iSocketServ, iBearers, aBearer, iMessageType, this, remoteAddr)) |
|
416 if (ret!=KErrNone) |
|
417 { |
|
418 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect: CActiveSocket Instantiate err=%d."), ret);) |
|
419 return ret; |
|
420 } |
|
421 iIsOpen=ETrue; |
|
422 } |
|
423 else |
|
424 { |
|
425 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect:Trying to Connect twice to the API."));) |
|
426 ret=KErrInUse; |
|
427 } |
|
428 return ret; |
|
429 } |
|
430 |
|
431 TInt CWapMessageApiAgent::Connect(const TDesC8& aRemoteHost, Wap::TPort aRemotePort, Wap::TBearer aBearer, TBool aSecure) |
|
432 /** |
|
433 Opens a socket which is to be used only with a single, named remote host. |
|
434 @internalComponent. |
|
435 @released since v8.0 |
|
436 @param aRemoteHost (In) the name of the remote host to connect. |
|
437 @param aRemotePort (In) the port of the remote host to connect. |
|
438 @param aBearer (In) the bearer to be used |
|
439 @param aSecure (In) security flag indicates whether WTLS will be used or not (Not Supported) |
|
440 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
441 */ |
|
442 { |
|
443 TInetAddr inetAddr( KInetAddrAny, 0); |
|
444 return (Connect(aRemoteHost, aRemotePort, aBearer, aSecure, inetAddr)); |
|
445 } |
|
446 |
|
447 TInt CWapMessageApiAgent::Connect(const TDesC8& aRemoteHost, Wap::TPort aRemotePort, Wap::TBearer aBearer, TBool /*aSecure*/, TInt aSocketServHandle, RConnection* aConnection) |
|
448 /** |
|
449 Opens a socket which is to be used only with a single, named remote host. |
|
450 @internalComponent. |
|
451 @released since v8.0 |
|
452 @param aRemoteHost (In) the name of the remote host to connect. |
|
453 @param aRemotePort (In) the port of the remote host to connect. |
|
454 @param aBearer (In) the bearer to be used |
|
455 @param aSecure (In) security flag indicates whether WTLS will be used or not (Not Supported) |
|
456 @param aSocketServHandle (In) The Socket Server ID. |
|
457 @param aConnection (In) The RConnection that shared with the client. |
|
458 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
459 */ |
|
460 { |
|
461 if (aBearer==Wap::EAll) |
|
462 { |
|
463 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::SendWspMessage:Connect to EAll Error"));) |
|
464 return Wap::EBearerError; |
|
465 } |
|
466 if (aSocketServHandle==0 || !aConnection) |
|
467 { |
|
468 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect:Parameter Error"));) |
|
469 return KErrArgument; |
|
470 } |
|
471 TInt ret=KErrNone; |
|
472 if (!iIsOpen) |
|
473 { |
|
474 iSocketServ.SetHandle(aSocketServHandle); |
|
475 TSockAddr remoteAddr; |
|
476 TRAP(ret, CSWSWapMsgUtils::BuildAddrL(remoteAddr, aBearer, aRemoteHost, aRemotePort)) |
|
477 if (ret!=KErrNone) |
|
478 { |
|
479 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect: BuildAddress err=%d."),ret);) |
|
480 return ret; |
|
481 } |
|
482 TRAP(ret, CActiveSocket::NewL(iSocketServ, iBearers, aBearer, iMessageType, this, remoteAddr, aConnection)) |
|
483 if (ret!=KErrNone) |
|
484 { |
|
485 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect: CActiveSocket Instantiate err=%d."),ret);) |
|
486 return ret; |
|
487 } |
|
488 iIsOpen=ETrue; |
|
489 } |
|
490 else |
|
491 { |
|
492 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::Connect:Connect to a connected API."));) |
|
493 ret=KErrInUse; |
|
494 } |
|
495 return ret; |
|
496 } |
|
497 // |
|
498 //CWspMessageApiAgent class Methods |
|
499 // |
|
500 CWspMessageApiAgent* CWspMessageApiAgent::NewL() |
|
501 /** |
|
502 Static NEWL() |
|
503 @internalComponent |
|
504 @released since v8.0 |
|
505 @returns CWspMessageApiAgent instance. |
|
506 */ |
|
507 { |
|
508 CWspMessageApiAgent* me = new(ELeave) CWspMessageApiAgent(); |
|
509 CleanupStack::PushL(me); |
|
510 me->ConstructL(); |
|
511 CleanupStack::Pop(me); |
|
512 return me; |
|
513 } |
|
514 |
|
515 CWspMessageApiAgent::CWspMessageApiAgent():CWapMessageApiAgent(EWapWsp) |
|
516 /** |
|
517 Constructor |
|
518 @internalComponent |
|
519 @released since v8.0 |
|
520 */ |
|
521 { |
|
522 } |
|
523 |
|
524 CWspMessageApiAgent::~CWspMessageApiAgent() |
|
525 /** |
|
526 Destructor |
|
527 @internalComponent |
|
528 @released since v8.0 |
|
529 */ |
|
530 { |
|
531 } |
|
532 |
|
533 void CWspMessageApiAgent::ConstructL() |
|
534 /** |
|
535 Second Phase Constructor |
|
536 @internalComponent |
|
537 @released since v8.0 |
|
538 */ |
|
539 { |
|
540 CWapMessageApiAgent::ConstructL(); |
|
541 } |
|
542 |
|
543 TInt CWspMessageApiAgent::SendWspMessage(Wap::TBearer aBearer, const TDesC8& aRemoteHost, Wap::TPort aRemotePort, TUint aMethod, const TDesC& aURI, const TDesC8& aReqHeaders, const TDesC8& aReqBody, TUint8 aTransactionId) |
|
544 /** |
|
545 Send Wsp Message to a remote host |
|
546 @internalComponent |
|
547 @released since v8.0 |
|
548 @param aBearer (in) the bearer to be used |
|
549 @param aRemoteHost (in) The remote host to be sent. |
|
550 @param aRemotePort (in) The remote port to be sent. |
|
551 @param aMethod (in) The method to be invoked. |
|
552 @param aURI (in) The destination URI. |
|
553 @param aReqHeaders (in) The Wsp header of WSP message. |
|
554 @param aReqBody (in) The Wsp body of WSP message. |
|
555 @param aTransactionId (in) The transaction ID of WSP message. |
|
556 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
557 */ |
|
558 { |
|
559 if (!iIsOpen) |
|
560 { |
|
561 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::SendWspMessage:Tryig to send to unconnected API"));) |
|
562 return KErrNotReady; |
|
563 } |
|
564 if (aBearer==Wap::EAll) |
|
565 { |
|
566 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::SendWspMessage:Send to EAll Error"));) |
|
567 return Wap::EBearerError; |
|
568 } |
|
569 HBufC8* sendBuf=NULL; |
|
570 TInt err=KErrNone; |
|
571 TSockAddr remoteAddr; |
|
572 TRAP(err, CSWSWapMsgUtils::BuildAddrL(remoteAddr, aBearer, aRemoteHost, aRemotePort)) |
|
573 if (err!=KErrNone) |
|
574 { |
|
575 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::SendWspMessage: BuildAddress err=%d."),err);) |
|
576 return err; |
|
577 } |
|
578 TRAP(err, CCLWSPPduHandler::PackWSPPduL(sendBuf, TWSPPduType(aMethod), aURI, aReqHeaders, aReqBody, aTransactionId)) |
|
579 if (err!=KErrNone) |
|
580 { |
|
581 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::SendWspMessage:Pack Wsp Packet Error=%d"),err);) |
|
582 return err; |
|
583 } |
|
584 CActiveSocket* sendSock=GetActiveSocketByBearer(aBearer); |
|
585 if (sendSock) |
|
586 { |
|
587 if (aBearer==Wap::ESMS||aBearer==Wap::EWAPSMS) |
|
588 { |
|
589 TWapSmsDataCodingScheme codingScheme = EWapSms8BitDCS; |
|
590 sendSock->Socket().SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,codingScheme); |
|
591 } |
|
592 TRequestStatus status; |
|
593 sendSock->Socket().SendTo(*sendBuf, remoteAddr, 0, status); |
|
594 User::WaitForRequest(status); |
|
595 err=status.Int(); |
|
596 } |
|
597 else |
|
598 { |
|
599 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::SendWspMessage: Can not find Bearer"));) |
|
600 err=Wap::EBearerError; |
|
601 } |
|
602 delete sendBuf; |
|
603 return err; |
|
604 } |
|
605 |
|
606 TInt CWspMessageApiAgent::SendWspMessage(TUint aMethod, const TDesC& aURI, const TDesC8& aReqHeaders, const TDesC8& aReqBody, TUint8 aTransactionId) |
|
607 /** |
|
608 Send Wsp Message to a remote host for fulluSpecified Interface |
|
609 @internalComponent |
|
610 @released since v8.0 |
|
611 @param aMethod (in) The method to be invoked. |
|
612 @param aURI (in) The destination URI. |
|
613 @param aReqHeaders (in) The Wsp header of WSP message. |
|
614 @param aReqBody (in) The Wsp body of WSP message. |
|
615 @param aTransactionId (in) The transaction ID of WSP message. |
|
616 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
617 */ |
|
618 { |
|
619 if (!iIsOpen) |
|
620 { |
|
621 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::SendWspMessage:Trying to send to unconnected API"));) |
|
622 return KErrNotReady; |
|
623 } |
|
624 if (!iBearers[0]) |
|
625 { |
|
626 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::SendWspMessage:No Bearer"));) |
|
627 return Wap::EBearerError; |
|
628 } |
|
629 HBufC8* sendBuf=NULL; |
|
630 TInt err=KErrNone; |
|
631 TRAP(err, CCLWSPPduHandler::PackWSPPduL(sendBuf, TWSPPduType(aMethod), aURI, aReqHeaders, aReqBody, aTransactionId)) |
|
632 if (err!=KErrNone) |
|
633 { |
|
634 LOG(SwsLog::Printf(_L("CWapMessageApiAgent::SendWspMessage:Pack Wsp Packet Error=%d"),err);) |
|
635 return err; |
|
636 } |
|
637 Wap::TBearer bearer=iBearers[0]->GetBearerType(); |
|
638 if (bearer==Wap::ESMS||bearer==Wap::EWAPSMS) |
|
639 { |
|
640 TWapSmsDataCodingScheme codingScheme = EWapSms8BitDCS; |
|
641 iBearers[0]->Socket().SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,codingScheme); |
|
642 } |
|
643 TSockAddr& remoteAddr=iBearers[0]->GetRemoteAddress(); |
|
644 TRequestStatus status; |
|
645 iBearers[0]->Socket().SendTo(*sendBuf, remoteAddr, 0, status); |
|
646 User::WaitForRequest(status); |
|
647 delete sendBuf; |
|
648 return status.Int(); |
|
649 } |
|
650 |
|
651 TInt CWspMessageApiAgent::ReceiveWspMessage(TDes8& aWspHeaders, TDes8& aWspBody, TPckgBuf<TUint8>& aTransactionIdPckg, TWSPStatus& aWspStatus, TRequestStatus& aReqStatus, TUint32 aTimeout) |
|
652 /** |
|
653 Receive the Wsp Message to a remote host for fulluSpecified Interface |
|
654 @internalComponent |
|
655 @released since v8.0 |
|
656 @param aWspHeaders (out) The Wsp header to be received |
|
657 @param aWspBody (out) The Wsp body to be received. |
|
658 @param aTransactionIdPckg (out) The received transaction ID buffer |
|
659 @param aWspStatus (out) The Wsp status for Method Result. |
|
660 @param aReqStatus (out) The request status of the WAP message API |
|
661 @param aTimeout (in) The timer out value. |
|
662 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
663 */ |
|
664 { |
|
665 TRequestStatus* reqStatus=NULL; |
|
666 if (!iIsOpen) |
|
667 { |
|
668 reqStatus=&aReqStatus; |
|
669 User::RequestComplete(reqStatus, KErrNotReady); |
|
670 LOG(SwsLog::Printf(_L("CWspMessageApiAgent::ReceiveWspMessage: Trying to recvive from unconnected API"));) |
|
671 return KErrNotReady; |
|
672 } |
|
673 if (iRequestActive) |
|
674 { |
|
675 reqStatus=&aReqStatus; |
|
676 User::RequestComplete(reqStatus, KErrInUse); |
|
677 LOG(SwsLog::Printf(_L("CWspMessageApiAgent::ReceiveWspMessage:Outstanding Receive exist"));) |
|
678 return KErrInUse; |
|
679 } |
|
680 //Record the client buffer |
|
681 iClientReqHeaders=&aWspHeaders; |
|
682 iClientReqBody=&aWspBody; |
|
683 iClientTransactionId=(TUint8*)aTransactionIdPckg.Ptr(); |
|
684 iClientWspStatus=&aWspStatus; |
|
685 //if there are data are being reading |
|
686 CActiveSocket* readingSock=GetActiveSocketByStatus(EReading); |
|
687 if (readingSock) |
|
688 { |
|
689 iRequestStatus=&aReqStatus; |
|
690 *iRequestStatus = KRequestPending; |
|
691 iRequestActive=ETrue; |
|
692 iLastReadingError=readingSock->GetWspData(*iClientReqHeaders, *iClientReqBody, *iClientTransactionId, *iClientWspStatus); |
|
693 if (iLastReadingError==KErrNone) |
|
694 { |
|
695 iLastPduBearer=readingSock->GetBearerType(); |
|
696 } |
|
697 iAsyncReadCompletion->CallBack(); |
|
698 return iLastReadingError; |
|
699 } |
|
700 //if there are pending data. |
|
701 CActiveSocket* pendingSock=GetActiveSocketByStatus(EPendingData); |
|
702 if (pendingSock) |
|
703 { |
|
704 iRequestStatus=&aReqStatus; |
|
705 *iRequestStatus = KRequestPending; |
|
706 iRequestActive=ETrue; |
|
707 iLastReadingError=pendingSock->GetWspData(*iClientReqHeaders, *iClientReqBody, *iClientTransactionId, *iClientWspStatus); |
|
708 if (iLastReadingError==KErrNone) |
|
709 { |
|
710 iLastPduBearer=pendingSock->GetBearerType(); |
|
711 } |
|
712 iAsyncReadCompletion->CallBack(); |
|
713 return iLastReadingError; |
|
714 } |
|
715 // Issue request in Idle socket |
|
716 CActiveSocket* sock=GetActiveSocketByStatus(EIdle); |
|
717 if (sock) |
|
718 { |
|
719 iRequestStatus=&aReqStatus; |
|
720 *iRequestStatus = KRequestPending; |
|
721 iRequestActive=ETrue; |
|
722 for (TInt i=0; i<iBearers.Count(); i++) |
|
723 { |
|
724 if (iBearers[i]->GetDataState()==EIdle) |
|
725 { |
|
726 iBearers[i]->AwaitRecvDataSize(); |
|
727 } |
|
728 } |
|
729 if (aTimeout>0) |
|
730 { |
|
731 iTimeoutTimer->After(aTimeout); |
|
732 } |
|
733 } |
|
734 return KErrNone; |
|
735 } |
|
736 |
|
737 void CWspMessageApiAgent::Notification(TInt aMessage, const TDesC8& aData) |
|
738 /** |
|
739 Notification of PDU size or PDU data |
|
740 @internalComponent |
|
741 @released since v8.0 |
|
742 @param aMessage (in) The Event Type received by the ActiveSocket |
|
743 @param aData (in)The Event received by the ActiveSocket. |
|
744 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
745 */ |
|
746 { |
|
747 LOG(SwsLog::Printf(_L("CWspMessageApiAgent::Notification is called"));) |
|
748 TWapNotificationInfo& info=*(reinterpret_cast<TWapNotificationInfo*>(const_cast<TUint8*>(aData.Ptr()))); |
|
749 Wap::TBearer bearer=info.iBearer; |
|
750 CActiveSocket* currentSocket=GetActiveSocketByBearer(bearer); |
|
751 ASSERT(currentSocket!=NULL); |
|
752 if (!currentSocket) |
|
753 { |
|
754 return; |
|
755 } |
|
756 TInt err=info.iError; |
|
757 switch (TWapNotificationEvent(aMessage)) |
|
758 { |
|
759 case EPduLengthReceived: |
|
760 { |
|
761 if (err!=KErrNone) |
|
762 { |
|
763 LOG(SwsLog::Printf(_L("CWspMessageApiAgent::Notification PDU length err status:%d"), err);) |
|
764 currentSocket->CleanUpData(); |
|
765 if (iRequestActive) |
|
766 { |
|
767 iTimeoutTimer->Cancel(); |
|
768 User::RequestComplete(iRequestStatus, err); |
|
769 iRequestActive=EFalse; |
|
770 } |
|
771 } |
|
772 else |
|
773 { |
|
774 LOG(SwsLog::Printf(_L("CWspMessageApiAgent::Notification PDU length is received"));) |
|
775 if ((err=currentSocket->Receive())!=KErrNone) |
|
776 { |
|
777 currentSocket->CleanUpData(); |
|
778 if (iRequestActive) |
|
779 { |
|
780 iTimeoutTimer->Cancel(); |
|
781 User::RequestComplete(iRequestStatus, err); |
|
782 iRequestActive=EFalse; |
|
783 } |
|
784 } |
|
785 } |
|
786 break; |
|
787 } |
|
788 case EPduReceived: |
|
789 { |
|
790 CActiveSocket* sock=GetActiveSocketByStatus(EReading); |
|
791 if (err!=KErrNone) |
|
792 { |
|
793 LOG(SwsLog::Printf(_L("CWspMessageApiAgent::Notification PDU data is received with Err status:%d"), err);) |
|
794 currentSocket->CleanUpData(); |
|
795 if (iRequestActive && !sock) |
|
796 { |
|
797 iTimeoutTimer->Cancel(); |
|
798 User::RequestComplete(iRequestStatus, err); |
|
799 iRequestActive=EFalse; |
|
800 } |
|
801 } |
|
802 else |
|
803 { |
|
804 LOG(SwsLog::Printf(_L("CWspMessageApiAgent::Notification PDU data is received"));) |
|
805 if (!sock && iRequestActive) |
|
806 { |
|
807 iTimeoutTimer->Cancel(); |
|
808 iRequestActive=EFalse; |
|
809 TRAP(err, currentSocket->UnpackPduToWspDataL()) |
|
810 if (err) |
|
811 { |
|
812 currentSocket->CleanUpData(); |
|
813 User::RequestComplete(iRequestStatus, err); |
|
814 return; |
|
815 } |
|
816 err=currentSocket->GetWspData(*iClientReqHeaders, *iClientReqBody, *iClientTransactionId, *iClientWspStatus); |
|
817 if (err==KErrNone) |
|
818 iLastPduBearer=bearer; |
|
819 User::RequestComplete(iRequestStatus, err); |
|
820 } |
|
821 } |
|
822 break; |
|
823 } |
|
824 default: |
|
825 LOG(SwsLog::Printf(_L("CWspMessageApiAgent::Notification() Unknown Event From Bearer"));) |
|
826 ; |
|
827 } |
|
828 } |
|
829 |
|
830 // |
|
831 //CWdpMessageApiAgent class Method |
|
832 // |
|
833 CWdpMessageApiAgent* CWdpMessageApiAgent::NewL() |
|
834 /** |
|
835 The static funtion to new a wdp message API agent |
|
836 @internalComponent |
|
837 @released since v8.0 |
|
838 @returns the CWdpMessageApiAgent instance |
|
839 */ |
|
840 { |
|
841 CWdpMessageApiAgent* me = new(ELeave) CWdpMessageApiAgent(); |
|
842 CleanupStack::PushL(me); |
|
843 me->ConstructL(); |
|
844 CleanupStack::Pop(me); |
|
845 return me; |
|
846 } |
|
847 |
|
848 CWdpMessageApiAgent::CWdpMessageApiAgent():CWapMessageApiAgent(EWapWdp) |
|
849 /** |
|
850 Constructor |
|
851 @internalComponent |
|
852 @released since v8.0 |
|
853 */ |
|
854 { |
|
855 } |
|
856 |
|
857 CWdpMessageApiAgent::~CWdpMessageApiAgent() |
|
858 /** |
|
859 Destructor |
|
860 @internalComponent |
|
861 @released since v8.0 |
|
862 */ |
|
863 { |
|
864 } |
|
865 |
|
866 void CWdpMessageApiAgent::ConstructL() |
|
867 /** |
|
868 Second Phase Constructor |
|
869 @internalComponent |
|
870 @released since v8.0 |
|
871 */ |
|
872 { |
|
873 CWapMessageApiAgent::ConstructL(); |
|
874 } |
|
875 |
|
876 TInt CWdpMessageApiAgent::ReceiveWdpMessage(TDes8& aRemoteHost, Wap::TPort& aRemotePort, TDes8& aBuffer, TBool& aTruncated, TRequestStatus& aReqStatus, TUint32 aTimeout) |
|
877 /** |
|
878 Receive WDP message from a remote host |
|
879 @internalComponent |
|
880 @released since v8.0 |
|
881 @param aRemoteHost (out) the remote host from which the WDP is sent |
|
882 @param aRemotePort (out) the remote port from which the WDP is sent |
|
883 @param aBuffer (out) the buffer to contain the received the WDP pdu |
|
884 @param aTruncated (out) the flag to show if the WDP PDU is trucated ot not |
|
885 @param aReqStatus (out) the client request status. |
|
886 @param aTimeOut (in) the time out value |
|
887 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
888 */ |
|
889 { |
|
890 TRequestStatus* reqStatus=NULL; |
|
891 TInt err=KErrNone; |
|
892 if (!iIsOpen) |
|
893 { |
|
894 reqStatus=&aReqStatus; |
|
895 User::RequestComplete(reqStatus, KErrNotReady); |
|
896 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::ReceiveWdpMessage:Recv From unconnected API"));) |
|
897 return KErrNotReady; |
|
898 } |
|
899 //if the length has been read |
|
900 CActiveSocket* sock=GetActiveSocketByStatus(EGotLength); |
|
901 CActiveSocket* sock1=GetActiveSocketByStatus(EReading); |
|
902 if (iRequestActive || (!sock && !sock1)) |
|
903 { |
|
904 reqStatus=&aReqStatus; |
|
905 User::RequestComplete(reqStatus, KErrInUse); |
|
906 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::ReceiveWdpMessage:in wrong state"));) |
|
907 return KErrInUse; |
|
908 } |
|
909 if (sock1) |
|
910 { |
|
911 Wap::TBearer bearer=sock1->GetBearerType(); |
|
912 TSockAddr& remoteAddr=sock1->GetRemoteAddress(); |
|
913 TRAP(err, CSWSWapMsgUtils::AnalyseAddrL(remoteAddr, bearer, *iClientRemoteHost, *iClientRemotePort)) |
|
914 if (err) |
|
915 { |
|
916 reqStatus=&aReqStatus; |
|
917 User::RequestComplete(reqStatus, err); |
|
918 return err; |
|
919 } |
|
920 iRequestStatus=&aReqStatus; |
|
921 *iRequestStatus = KRequestPending; |
|
922 iRequestActive=ETrue; |
|
923 iLastReadingError=sock1->GetPduData(*iClientPduBuffer, *iClientTruncated); |
|
924 if (!iLastReadingError) |
|
925 { |
|
926 iLastPduBearer=bearer; |
|
927 } |
|
928 iAsyncReadCompletion->CallBack(); |
|
929 return iLastReadingError; |
|
930 } |
|
931 if (sock) |
|
932 { |
|
933 if ((err=sock->Receive())==KErrNone) |
|
934 { |
|
935 iClientPduBuffer=&aBuffer; |
|
936 iClientRemoteHost=&aRemoteHost; |
|
937 iClientRemotePort=&aRemotePort; |
|
938 iClientTruncated=&aTruncated; |
|
939 iRequestStatus=&aReqStatus; |
|
940 *iRequestStatus = KRequestPending; |
|
941 iRequestActive=ETrue; |
|
942 if (aTimeout) |
|
943 { |
|
944 iTimeoutTimer->After(aTimeout); |
|
945 } |
|
946 } |
|
947 else |
|
948 { |
|
949 reqStatus=&aReqStatus; |
|
950 User::RequestComplete(reqStatus, err); |
|
951 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::ReceiveWdpMessage:err=%d"), err);) |
|
952 return err; |
|
953 } |
|
954 } |
|
955 return KErrNone; |
|
956 } |
|
957 |
|
958 TInt CWdpMessageApiAgent::AwaitRecvDataSize(TPckg<TUint16>& aDataSizePckg, TRequestStatus& aReqStatus) |
|
959 /** |
|
960 Receive WDP message PDU length from a remote host |
|
961 @internalComponent |
|
962 @released since v8.0 |
|
963 @param aDataSizePckg (out) the length of the PDU |
|
964 @param aReqStatus (out) the client request status. |
|
965 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
966 */ |
|
967 { |
|
968 TRequestStatus* reqStatus=NULL; |
|
969 if (!iIsOpen) |
|
970 { |
|
971 reqStatus=&aReqStatus; |
|
972 User::RequestComplete(reqStatus, KErrNotReady); |
|
973 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::AwaitRecvDataSize:Wait For Data length From unconnected API"));) |
|
974 return KErrNotReady; |
|
975 } |
|
976 //if the length has been read or there is some data pending, then error completion |
|
977 CActiveSocket* sock=GetActiveSocketByStatus(EGotLength); |
|
978 CActiveSocket* sock1=GetActiveSocketByStatus(ERequestingData); |
|
979 CActiveSocket* sock2=GetActiveSocketByStatus(EReading); |
|
980 if (iRequestActive||sock||sock1||sock2) |
|
981 { |
|
982 reqStatus=&aReqStatus; |
|
983 User::RequestComplete(reqStatus, KErrInUse); |
|
984 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::AwaitRecvDataSize:in wrong state"));) |
|
985 return KErrInUse; |
|
986 } |
|
987 //if there is a pending length, then get it |
|
988 sock=GetActiveSocketByStatus(EPendingLength); |
|
989 if (sock) |
|
990 { |
|
991 iClientDataSize=&aDataSizePckg; |
|
992 iRequestStatus=&aReqStatus; |
|
993 *iRequestStatus = KRequestPending; |
|
994 iRequestActive=ETrue; |
|
995 TUint16 length=(TUint16)sock->GetPduSize(); |
|
996 TPckg<TUint16> des(length); |
|
997 iClientDataSize->Copy(des); |
|
998 iLastReadingError=KErrNone; |
|
999 iAsyncReadCompletion->CallBack(); |
|
1000 return KErrNone; |
|
1001 } |
|
1002 //if there is some idle socket, then wait for length |
|
1003 sock=GetActiveSocketByStatus(EIdle); |
|
1004 if (sock) |
|
1005 { |
|
1006 iRequestActive=ETrue; |
|
1007 iClientDataSize=&aDataSizePckg; |
|
1008 iRequestStatus=&aReqStatus; |
|
1009 *iRequestStatus = KRequestPending; |
|
1010 //Wait for length on the idle socket |
|
1011 for (TInt i=0; i<iBearers.Count(); i++) |
|
1012 { |
|
1013 if (iBearers[i]->GetDataState()==EIdle) |
|
1014 { |
|
1015 iBearers[i]->AwaitRecvDataSize(); |
|
1016 } |
|
1017 } |
|
1018 } |
|
1019 return KErrNone; |
|
1020 } |
|
1021 |
|
1022 TInt CWdpMessageApiAgent::SendWdpMessage(const TDesC8& aBuffer, const TDesC8& aRemoteHost, Wap::TPort aRemotePort, Wap::TBearer aBearer) |
|
1023 /** |
|
1024 Send WDP message to a remote host |
|
1025 @internalComponent |
|
1026 @released since v8.0 |
|
1027 @param aBuffer (in) the data to be sent |
|
1028 @param aRemoteHost (in) the remote host to be sent |
|
1029 @param aRemotePort (in) the remote port to be sent |
|
1030 @param aBearer (in) the Bearer to be used |
|
1031 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
1032 */ |
|
1033 { |
|
1034 if (!iIsOpen) |
|
1035 { |
|
1036 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::SendWdpMessage:Send WDP to unconnected API"));) |
|
1037 return KErrNotReady; |
|
1038 } |
|
1039 if (aBearer==Wap::EAll) |
|
1040 { |
|
1041 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::SendWdpMessage:Wrong Bearer"));) |
|
1042 return Wap::EBearerError; |
|
1043 } |
|
1044 TSockAddr remoteAddr; |
|
1045 TInt err=KErrNone; |
|
1046 TRAP(err, CSWSWapMsgUtils::BuildAddrL(remoteAddr, aBearer, aRemoteHost, aRemotePort)) |
|
1047 if (err) |
|
1048 { |
|
1049 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::SendWdpMessage:BuildAddrL Err=%d"), err);) |
|
1050 return err; |
|
1051 } |
|
1052 CActiveSocket* sendSock=GetActiveSocketByBearer(aBearer); |
|
1053 if (sendSock) |
|
1054 { |
|
1055 if (aBearer==Wap::ESMS||aBearer==Wap::EWAPSMS) |
|
1056 { |
|
1057 TWapSmsDataCodingScheme codingScheme = EWapSms8BitDCS; |
|
1058 sendSock->Socket().SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,codingScheme); |
|
1059 } |
|
1060 TRequestStatus status; |
|
1061 sendSock->Socket().SendTo(aBuffer, remoteAddr, 0, status); |
|
1062 User::WaitForRequest(status); |
|
1063 err=status.Int(); |
|
1064 } |
|
1065 else |
|
1066 { |
|
1067 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::SendWdpMessage:No Bearer"));) |
|
1068 err=Wap::EBearerError; |
|
1069 } |
|
1070 return err; |
|
1071 } |
|
1072 |
|
1073 TInt CWdpMessageApiAgent::SendWdpMessage(const TDesC8& aBuffer) |
|
1074 /** |
|
1075 Send WDP message to a remote host |
|
1076 @internalComponent |
|
1077 @released since v8.0 |
|
1078 @param aBuffer (in) the data to be sent |
|
1079 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
1080 */ |
|
1081 { |
|
1082 if (!iIsOpen) |
|
1083 { |
|
1084 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::SendWdpMessage:Send WDP to unconnected API"));) |
|
1085 return KErrNotReady; |
|
1086 } |
|
1087 if (!iBearers[0]) |
|
1088 { |
|
1089 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::SendWdpMessage:No Bearer"));) |
|
1090 return Wap::EBearerError; |
|
1091 } |
|
1092 Wap::TBearer bearer=iBearers[0]->GetBearerType(); |
|
1093 if (bearer==Wap::ESMS||bearer==Wap::EWAPSMS) |
|
1094 { |
|
1095 TWapSmsDataCodingScheme codingScheme = EWapSms8BitDCS; |
|
1096 iBearers[0]->Socket().SetOpt(KWapSmsOptionNameDCS,KWapSmsOptionLevel,codingScheme); |
|
1097 } |
|
1098 TSockAddr& remoteAddr=iBearers[0]->GetRemoteAddress(); |
|
1099 TRequestStatus status; |
|
1100 iBearers[0]->Socket().SendTo(aBuffer, remoteAddr, 0, status); |
|
1101 User::WaitForRequest(status); |
|
1102 return status.Int(); |
|
1103 } |
|
1104 |
|
1105 void CWdpMessageApiAgent::Notification(TInt aMessage, const TDesC8& aData) |
|
1106 /** |
|
1107 Notification from the ActiveSocket |
|
1108 @internalComponent |
|
1109 @released since v8.0 |
|
1110 @param aMessage (in) the Event Type |
|
1111 @param aData (in) the Event |
|
1112 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
1113 */ |
|
1114 { |
|
1115 TWapNotificationInfo& info=*(reinterpret_cast<TWapNotificationInfo*>(const_cast<TUint8*>(aData.Ptr()))); |
|
1116 Wap::TBearer bearer=info.iBearer; |
|
1117 CActiveSocket* currentSocket=GetActiveSocketByBearer(bearer); |
|
1118 ASSERT(currentSocket!=NULL); |
|
1119 if (!currentSocket) |
|
1120 { |
|
1121 return; |
|
1122 } |
|
1123 TInt err=info.iError; |
|
1124 switch (TWapNotificationEvent(aMessage)) |
|
1125 { |
|
1126 case EPduLengthReceived: |
|
1127 { |
|
1128 CActiveSocket* sock1=GetActiveSocketByStatus(ERequestingData); |
|
1129 CActiveSocket* sock2=GetActiveSocketByStatus(EGotLength); |
|
1130 CActiveSocket* sock3=GetActiveSocketByStatus(EReading); |
|
1131 if (!sock1 && !sock2 && !sock3 && iRequestActive) |
|
1132 // Read pdu length from this socket |
|
1133 { |
|
1134 iRequestActive=EFalse; |
|
1135 if (err==KErrNone) |
|
1136 { |
|
1137 TUint16 length=(TUint16)currentSocket->GetPduSize(); |
|
1138 TPckg<TUint16> des(length); |
|
1139 iClientDataSize->Copy(des); |
|
1140 } |
|
1141 else |
|
1142 { |
|
1143 currentSocket->CleanUpData(); |
|
1144 } |
|
1145 User::RequestComplete(iRequestStatus, err); |
|
1146 } |
|
1147 break; |
|
1148 } |
|
1149 case EPduReceived: |
|
1150 { |
|
1151 ASSERT(iRequestActive); |
|
1152 if (iRequestActive) |
|
1153 { |
|
1154 // Read pdu from this socket |
|
1155 iRequestActive=EFalse; |
|
1156 iTimeoutTimer->Cancel(); |
|
1157 if (err==KErrNone) |
|
1158 { |
|
1159 TSockAddr& remoteAddr=currentSocket->GetRemoteAddress(); |
|
1160 TRAP(err, CSWSWapMsgUtils::AnalyseAddrL(remoteAddr, bearer, *iClientRemoteHost, *iClientRemotePort)) |
|
1161 if (!err) |
|
1162 { |
|
1163 err=currentSocket->GetPduData(*iClientPduBuffer, *iClientTruncated); |
|
1164 if (!err) |
|
1165 iLastPduBearer=bearer; |
|
1166 } |
|
1167 else |
|
1168 { |
|
1169 currentSocket->SetDataState(EReading); |
|
1170 } |
|
1171 } |
|
1172 else |
|
1173 { |
|
1174 currentSocket->CleanUpData(); |
|
1175 } |
|
1176 User::RequestComplete(iRequestStatus, err); |
|
1177 } |
|
1178 } |
|
1179 break; |
|
1180 default: |
|
1181 LOG(SwsLog::Printf(_L("CWdpMessageApiAgent::Notification() Unknown Event From Bearer"));) |
|
1182 ; |
|
1183 } |
|
1184 } |