0
|
1 |
/*
|
|
2 |
* Copyright (c) 2004-2005 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
1
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
0
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
1
|
14 |
* Description:
|
0
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#define TRACE_PREFIX "WSOCK: Agent: "
|
|
20 |
#include "wsock.h"
|
|
21 |
#include "WinsockAgent.h"
|
|
22 |
#include "WinsockAgentCallback.h"
|
|
23 |
#include "WinsockProtocolFamily.h"
|
|
24 |
|
|
25 |
#ifdef SYMBIAN_NETWORKING_PLATSEC
|
|
26 |
#define ACCESS_METHOD1(_ret,_what,_p1) \
|
|
27 |
_ret CWinsockAgent::Do##_what(_p1, const RMessagePtr2* /*aMessage*/ )
|
|
28 |
#define ACCESS_METHOD2(_ret,_what,_p1,_p2) \
|
|
29 |
_ret CWinsockAgent::Do##_what(_p1, _p2, const RMessagePtr2* /*aMessage*/ )
|
|
30 |
#else /* SYMBIAN_NETWORKING_PLATSEC */
|
|
31 |
#define ACCESS_METHOD1(_ret,_what,_p1) \
|
|
32 |
_ret CWinsockAgent::_what(_p1)
|
|
33 |
#define ACCESS_METHOD2(_ret,_what,_p1,_p2) \
|
|
34 |
_ret CWinsockAgent::_what(_p1,_p2)
|
|
35 |
#endif /* SYMBIAN_NETWORKING_PLATSEC */
|
|
36 |
|
|
37 |
// Settings
|
|
38 |
_LIT(KIfName,"IfName"); // IF_NAME
|
|
39 |
_LIT(KIfNetworks,"IfNetworks"); // SERVICE_IF_NETWORKS
|
|
40 |
_LIT(KIAPBearerType,"IAP\\IAPBearerType");
|
|
41 |
_LIT(KIAPServiceType,"IAP\\IAPServiceType");
|
|
42 |
_LIT(KIAPName,"IAP\\Name");
|
|
43 |
_LIT(KIAPId,"IAP\\Id");
|
|
44 |
_LIT(KIAPService,"IAP\\IAPService");
|
|
45 |
_LIT(KIAPNetwork,"IAP\\IAPNetwork");
|
|
46 |
_LIT(KLANBearerName,"LANBearer\\Name");
|
|
47 |
_LIT(KLANBearerLastSocketActivityTimeout,"LANBearer\\LastSocketActivityTimeout");
|
|
48 |
_LIT(KLANBearerLastSocketActivityTimeout2,"LastSocketActivityTimeout");
|
|
49 |
_LIT(KLANBearerLastSessionClosedTimeout,"LANBearer\\LastSessionClosedTimeout");
|
|
50 |
_LIT(KLANBearerLastSessionClosedTimeout2,"LastSessionClosedTimeout");
|
|
51 |
_LIT(KLANBearerLastSocketClosedTimeout,"LANBearer\\LastSocketClosedTimeout");
|
|
52 |
_LIT(KLANBearerLastSocketClosedTimeout2,"LastSocketClosedTimeout");
|
|
53 |
|
|
54 |
CWinsockAgent* CWinsockAgent::NewL()
|
|
55 |
{
|
|
56 |
CWinsockAgent* self = new(ELeave)CWinsockAgent;
|
|
57 |
CleanupStack::PushL(self);
|
|
58 |
self->ConstructL();
|
|
59 |
CleanupStack::Pop(self);
|
|
60 |
return self;
|
|
61 |
}
|
|
62 |
|
|
63 |
CWinsockAgent::CWinsockAgent()
|
|
64 |
{
|
|
65 |
}
|
|
66 |
|
|
67 |
CWinsockAgent::~CWinsockAgent()
|
|
68 |
{
|
|
69 |
if (iConnector)
|
|
70 |
{
|
|
71 |
iConnector->Cancel();
|
|
72 |
delete iConnector;
|
|
73 |
}
|
|
74 |
if (iDisconnector)
|
|
75 |
{
|
|
76 |
iDisconnector->Cancel();
|
|
77 |
delete iDisconnector;
|
|
78 |
}
|
1
|
79 |
|
|
80 |
|
0
|
81 |
}
|
|
82 |
|
|
83 |
void CWinsockAgent::ConstructL()
|
|
84 |
{
|
|
85 |
WsockCheckCommDbL(iIapId, iIapNetwork, iIapService, iIapBearer);
|
|
86 |
}
|
|
87 |
|
|
88 |
void CWinsockAgent::Info(TNifAgentInfo& aInfo) const
|
|
89 |
{
|
|
90 |
aInfo.iVersion = TVersion(1,0,0);
|
|
91 |
aInfo.iName = KWinsockAgent;
|
|
92 |
}
|
|
93 |
|
|
94 |
void CWinsockAgent::Connect(TAgentConnectType aType)
|
|
95 |
{
|
|
96 |
Connect(aType, NULL);
|
|
97 |
}
|
|
98 |
|
|
99 |
void CWinsockAgent::Connect(TAgentConnectType DEBUG_ONLY(aType),
|
|
100 |
CStoreableOverrideSettings* /*aOverride*/)
|
|
101 |
{
|
|
102 |
TRACE1("Connect(%d)",aType);
|
|
103 |
ASSERT(iNotify);
|
|
104 |
ScheduleConnectNotification();
|
|
105 |
iNotify->ServiceStarted();
|
|
106 |
}
|
|
107 |
|
|
108 |
void CWinsockAgent::CancelConnect()
|
|
109 |
{
|
|
110 |
TRACE("CancelConnect()");
|
|
111 |
CancelConnectNotification();
|
|
112 |
}
|
|
113 |
|
|
114 |
void CWinsockAgent::Reconnect()
|
|
115 |
{
|
|
116 |
TRACE("Reconnect()");
|
|
117 |
ScheduleConnectNotification();
|
|
118 |
}
|
|
119 |
|
|
120 |
void CWinsockAgent::CancelReconnect()
|
|
121 |
{
|
|
122 |
TRACE("CancelReconnect()");
|
|
123 |
CancelConnectNotification();
|
|
124 |
}
|
|
125 |
|
|
126 |
void CWinsockAgent::Authenticate(TDes& /*aUsername*/, TDes& /*aPassword*/)
|
|
127 |
{
|
|
128 |
TRACE("Authenticate()");
|
|
129 |
ASSERT(iNotify);
|
|
130 |
iNotify->AuthenticateComplete(KErrNone);
|
|
131 |
}
|
|
132 |
|
|
133 |
void CWinsockAgent::CancelAuthenticate()
|
|
134 |
{
|
|
135 |
TRACE("CancelAuthenticate()");
|
|
136 |
}
|
|
137 |
|
|
138 |
void CWinsockAgent::Disconnect(TInt aReason)
|
|
139 |
{
|
|
140 |
TRACE1("Disconnect(%d)",aReason);
|
|
141 |
iDisconnectReason = aReason;
|
|
142 |
if (!iDisconnector)
|
|
143 |
{
|
|
144 |
iDisconnector = new CWinsockAgentCallback(this,DisconnectComplete);
|
|
145 |
}
|
|
146 |
if (iDisconnector)
|
|
147 |
{
|
|
148 |
// Schedule asynchronous disconnect notification
|
|
149 |
ASSERT(iDisconnector->Agent() == this);
|
|
150 |
iDisconnector->InvokeLater();
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
TInt CWinsockAgent::GetExcessData(TDes8& aBuffer)
|
|
155 |
{
|
|
156 |
TRACE("GetExcessData()");
|
|
157 |
aBuffer.SetLength(0);
|
|
158 |
return KErrNone;
|
|
159 |
}
|
|
160 |
|
|
161 |
ACCESS_METHOD2(TInt, ReadInt, const TDesC& aField, TUint32& aValue)
|
|
162 |
{
|
|
163 |
if (aField == KIAPId)
|
|
164 |
{
|
|
165 |
aValue = iIapId;
|
|
166 |
}
|
|
167 |
else if (aField == KIAPNetwork)
|
|
168 |
{
|
|
169 |
aValue = iIapNetwork;
|
|
170 |
}
|
|
171 |
else if (aField == KIAPService)
|
|
172 |
{
|
|
173 |
aValue = iIapService;
|
|
174 |
}
|
|
175 |
else if (aField == KLANBearerLastSocketActivityTimeout ||
|
|
176 |
aField == KLANBearerLastSocketActivityTimeout2)
|
|
177 |
{
|
|
178 |
aValue = KWinsockSocketActivityTimeout;
|
|
179 |
}
|
|
180 |
else if (aField == KLANBearerLastSessionClosedTimeout ||
|
|
181 |
aField == KLANBearerLastSessionClosedTimeout2)
|
|
182 |
{
|
|
183 |
aValue = KWinsockSessionClosedTimeout;
|
|
184 |
}
|
|
185 |
else if (aField == KLANBearerLastSocketClosedTimeout ||
|
|
186 |
aField == KLANBearerLastSocketClosedTimeout2)
|
|
187 |
{
|
|
188 |
aValue = KWinsockSocketClosedTimeout;
|
|
189 |
}
|
|
190 |
else
|
|
191 |
{
|
|
192 |
TRACE1("ReadInt(%S) -> KErrNotFound",&aField);
|
|
193 |
return KErrNotFound;
|
|
194 |
}
|
|
195 |
TRACE2("ReadInt(%S) = %d",&aField,aValue);
|
|
196 |
return KErrNone;
|
|
197 |
}
|
|
198 |
|
|
199 |
ACCESS_METHOD2(TInt, WriteInt, const TDesC& DEBUG_ONLY(aField),
|
|
200 |
TUint32 DEBUG_ONLY(aValue))
|
|
201 |
{
|
|
202 |
TRACE2("WriteInt(%S,%d)",&aField,aValue);
|
|
203 |
return KErrNotSupported;
|
|
204 |
}
|
|
205 |
|
|
206 |
ACCESS_METHOD2(TInt, ReadDes, const TDesC& DEBUG_ONLY(aField),
|
|
207 |
TDes8& /*aValue*/)
|
|
208 |
{
|
|
209 |
TRACE1("ReadDes8(%S)",&aField);
|
|
210 |
return KErrNotFound;
|
|
211 |
}
|
|
212 |
|
|
213 |
ACCESS_METHOD2(TInt, WriteDes, const TDesC& DEBUG_ONLY(aField),
|
|
214 |
const TDesC8& /*aValue*/)
|
|
215 |
{
|
|
216 |
TRACE1("WriteDes8(%S)",&aField);
|
|
217 |
return KErrNotSupported;
|
|
218 |
}
|
|
219 |
|
|
220 |
ACCESS_METHOD2(TInt, ReadDes, const TDesC& aField, TDes16& aValue)
|
|
221 |
{
|
|
222 |
if (aField == KIfName)
|
|
223 |
{
|
|
224 |
aValue = KWinsockInterface;
|
|
225 |
}
|
|
226 |
else if (aField == KIfNetworks)
|
|
227 |
{
|
|
228 |
CWinsockProtocolFamily::ProtocolNames(aValue);
|
|
229 |
}
|
|
230 |
else if (aField == KIAPBearerType)
|
|
231 |
{
|
|
232 |
aValue = KWinsockBearerType;
|
|
233 |
}
|
|
234 |
else if (aField == KIAPServiceType)
|
|
235 |
{
|
|
236 |
aValue = KWinsockServiceType;
|
|
237 |
}
|
|
238 |
else if (aField == KIAPName)
|
|
239 |
{
|
|
240 |
aValue = KWinsockAPName;
|
|
241 |
}
|
|
242 |
else if (aField == KLANBearerName)
|
|
243 |
{
|
|
244 |
aValue = KWinsockBearerName;
|
|
245 |
}
|
|
246 |
else
|
|
247 |
{
|
|
248 |
TRACE1("ReadDes16(%S) -> KErrNotFound",&aField);
|
|
249 |
return KErrNotFound;
|
|
250 |
}
|
|
251 |
TRACE2("ReadDes16(%S) = %S",&aField,&aValue);
|
|
252 |
return KErrNone;
|
|
253 |
}
|
|
254 |
|
|
255 |
ACCESS_METHOD2(TInt, WriteDes, const TDesC& DEBUG_ONLY(aField),
|
|
256 |
const TDesC16& /*aValue*/)
|
|
257 |
{
|
|
258 |
TRACE1("WriteDes16(%S)",&aField);
|
|
259 |
return KErrNotSupported;
|
|
260 |
}
|
|
261 |
|
|
262 |
ACCESS_METHOD2(TInt, ReadBool, const TDesC& DEBUG_ONLY(aField),
|
|
263 |
TBool& /*aValue*/)
|
|
264 |
{
|
|
265 |
TRACE1("ReadBool(%S)",&aField);
|
|
266 |
return KErrNotFound;
|
|
267 |
}
|
|
268 |
|
|
269 |
ACCESS_METHOD2(TInt, WriteBool, const TDesC& DEBUG_ONLY(aField),
|
|
270 |
TBool DEBUG_ONLY(aValue))
|
|
271 |
{
|
|
272 |
TRACE2("WriteBool(%S,%d)",&aField,aValue);
|
|
273 |
return KErrNotSupported;
|
|
274 |
}
|
|
275 |
|
|
276 |
ACCESS_METHOD1(HBufC*, ReadLongDesLC, const TDesC& DEBUG_ONLY(aField))
|
|
277 |
{
|
|
278 |
TRACE1("ReadLongDesLC(%S)",&aField);
|
|
279 |
return NULL;
|
|
280 |
}
|
|
281 |
|
|
282 |
TInt CWinsockAgent::Notification(TNifToAgentEventType DEBUG_ONLY(aEvent),
|
|
283 |
TAny* /*aInfo*/)
|
|
284 |
{
|
|
285 |
TRACE1("Notification(%d)",aEvent);
|
|
286 |
return KErrNotSupported;
|
|
287 |
}
|
|
288 |
|
|
289 |
TInt CWinsockAgent::IncomingConnectionReceived()
|
|
290 |
{
|
|
291 |
TRACE("IncomingConnectionReceived()");
|
|
292 |
return KErrNotSupported;
|
|
293 |
}
|
|
294 |
|
|
295 |
void CWinsockAgent::GetLastError(TInt& aError)
|
|
296 |
{
|
|
297 |
TRACE("GetLastError()");
|
|
298 |
aError = KErrNone;
|
|
299 |
}
|
|
300 |
|
|
301 |
TBool CWinsockAgent::IsActive() const
|
|
302 |
{
|
|
303 |
return ETrue;
|
|
304 |
}
|
|
305 |
|
|
306 |
TBool CWinsockAgent::IsReconnect() const
|
|
307 |
{
|
|
308 |
return EFalse;
|
|
309 |
}
|
|
310 |
|
|
311 |
void CWinsockAgent::SetConnectionSettingsL(const TConnectionSettings& aSettings)
|
|
312 |
{
|
|
313 |
TRACE("SetConnectionSettingsL()");
|
|
314 |
iSettings = aSettings;
|
|
315 |
}
|
|
316 |
|
|
317 |
TConnectionSettings& CWinsockAgent::ConnectionSettingsL()
|
|
318 |
{
|
|
319 |
TRACE("ConnectionSettingsL()");
|
|
320 |
return iSettings;
|
|
321 |
}
|
|
322 |
|
|
323 |
void CWinsockAgent::SetOverridesL(CStoreableOverrideSettings* /*aOverride*/)
|
|
324 |
{
|
|
325 |
TRACE("SetOverridesL()");
|
|
326 |
}
|
|
327 |
|
|
328 |
CStoreableOverrideSettings* CWinsockAgent::OverridesL()
|
|
329 |
{
|
|
330 |
TRACE("OverridesL()");
|
|
331 |
User::Leave(KErrNotSupported);
|
|
332 |
return NULL;
|
|
333 |
}
|
|
334 |
|
|
335 |
void CWinsockAgent::RequestNotificationOfServiceChangeL(
|
|
336 |
MAgentSessionNotify* /*aSession*/)
|
|
337 |
{
|
|
338 |
User::Leave(KErrNotSupported);
|
|
339 |
}
|
|
340 |
|
|
341 |
void CWinsockAgent::CancelRequestNotificationOfServiceChange(
|
|
342 |
MAgentSessionNotify* /*aSession*/)
|
|
343 |
{
|
|
344 |
}
|
|
345 |
|
|
346 |
// Private methods
|
|
347 |
|
|
348 |
void CWinsockAgent::ScheduleConnectNotification()
|
|
349 |
{
|
|
350 |
ASSERT(iNotify);
|
|
351 |
if (!iConnector && iNotify)
|
|
352 |
{
|
|
353 |
iConnector = new CWinsockAgentCallback(this,ConnectComplete);
|
|
354 |
}
|
|
355 |
if (iConnector)
|
|
356 |
{
|
|
357 |
// Schedule asynchronous connect notification
|
|
358 |
ASSERT(iConnector->Agent() == this);
|
|
359 |
iConnector->InvokeLater();
|
|
360 |
}
|
|
361 |
}
|
|
362 |
|
|
363 |
void CWinsockAgent::CancelConnectNotification()
|
|
364 |
{
|
|
365 |
if (iConnector)
|
|
366 |
{
|
|
367 |
iConnector->Cancel();
|
|
368 |
}
|
|
369 |
}
|
|
370 |
|
|
371 |
void CWinsockAgent::ConnectComplete()
|
|
372 |
{
|
|
373 |
TRACE("firing connection notification");
|
|
374 |
iNotify->AgentProgress(KConnectionOpen, KErrNone);
|
|
375 |
iNotify->ConnectComplete(KErrNone);
|
|
376 |
}
|
|
377 |
|
|
378 |
void CWinsockAgent::DisconnectComplete()
|
|
379 |
{
|
|
380 |
TRACE("firing disconnect notification");
|
|
381 |
iNotify->AgentProgress(KConnectionClosed, iDisconnectReason);
|
|
382 |
iNotify->DisconnectComplete();
|
|
383 |
}
|