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