|
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 |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
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 } |
|
79 } |
|
80 |
|
81 void CWinsockAgent::ConstructL() |
|
82 { |
|
83 WsockCheckCommDbL(iIapId, iIapNetwork, iIapService, iIapBearer); |
|
84 } |
|
85 |
|
86 void CWinsockAgent::Info(TNifAgentInfo& aInfo) const |
|
87 { |
|
88 aInfo.iVersion = TVersion(1,0,0); |
|
89 aInfo.iName = KWinsockAgent; |
|
90 } |
|
91 |
|
92 void CWinsockAgent::Connect(TAgentConnectType aType) |
|
93 { |
|
94 Connect(aType, NULL); |
|
95 } |
|
96 |
|
97 void CWinsockAgent::Connect(TAgentConnectType DEBUG_ONLY(aType), |
|
98 CStoreableOverrideSettings* /*aOverride*/) |
|
99 { |
|
100 TRACE1("Connect(%d)",aType); |
|
101 ASSERT(iNotify); |
|
102 ScheduleConnectNotification(); |
|
103 iNotify->ServiceStarted(); |
|
104 } |
|
105 |
|
106 void CWinsockAgent::CancelConnect() |
|
107 { |
|
108 TRACE("CancelConnect()"); |
|
109 CancelConnectNotification(); |
|
110 } |
|
111 |
|
112 void CWinsockAgent::Reconnect() |
|
113 { |
|
114 TRACE("Reconnect()"); |
|
115 ScheduleConnectNotification(); |
|
116 } |
|
117 |
|
118 void CWinsockAgent::CancelReconnect() |
|
119 { |
|
120 TRACE("CancelReconnect()"); |
|
121 CancelConnectNotification(); |
|
122 } |
|
123 |
|
124 void CWinsockAgent::Authenticate(TDes& /*aUsername*/, TDes& /*aPassword*/) |
|
125 { |
|
126 TRACE("Authenticate()"); |
|
127 ASSERT(iNotify); |
|
128 iNotify->AuthenticateComplete(KErrNone); |
|
129 } |
|
130 |
|
131 void CWinsockAgent::CancelAuthenticate() |
|
132 { |
|
133 TRACE("CancelAuthenticate()"); |
|
134 } |
|
135 |
|
136 void CWinsockAgent::Disconnect(TInt aReason) |
|
137 { |
|
138 TRACE1("Disconnect(%d)",aReason); |
|
139 iDisconnectReason = aReason; |
|
140 if (!iDisconnector) |
|
141 { |
|
142 iDisconnector = new CWinsockAgentCallback(this,DisconnectComplete); |
|
143 } |
|
144 if (iDisconnector) |
|
145 { |
|
146 // Schedule asynchronous disconnect notification |
|
147 ASSERT(iDisconnector->Agent() == this); |
|
148 iDisconnector->InvokeLater(); |
|
149 } |
|
150 } |
|
151 |
|
152 TInt CWinsockAgent::GetExcessData(TDes8& aBuffer) |
|
153 { |
|
154 TRACE("GetExcessData()"); |
|
155 aBuffer.SetLength(0); |
|
156 return KErrNone; |
|
157 } |
|
158 |
|
159 ACCESS_METHOD2(TInt, ReadInt, const TDesC& aField, TUint32& aValue) |
|
160 { |
|
161 if (aField == KIAPId) |
|
162 { |
|
163 aValue = iIapId; |
|
164 } |
|
165 else if (aField == KIAPNetwork) |
|
166 { |
|
167 aValue = iIapNetwork; |
|
168 } |
|
169 else if (aField == KIAPService) |
|
170 { |
|
171 aValue = iIapService; |
|
172 } |
|
173 else if (aField == KLANBearerLastSocketActivityTimeout || |
|
174 aField == KLANBearerLastSocketActivityTimeout2) |
|
175 { |
|
176 aValue = KWinsockSocketActivityTimeout; |
|
177 } |
|
178 else if (aField == KLANBearerLastSessionClosedTimeout || |
|
179 aField == KLANBearerLastSessionClosedTimeout2) |
|
180 { |
|
181 aValue = KWinsockSessionClosedTimeout; |
|
182 } |
|
183 else if (aField == KLANBearerLastSocketClosedTimeout || |
|
184 aField == KLANBearerLastSocketClosedTimeout2) |
|
185 { |
|
186 aValue = KWinsockSocketClosedTimeout; |
|
187 } |
|
188 else |
|
189 { |
|
190 TRACE1("ReadInt(%S) -> KErrNotFound",&aField); |
|
191 return KErrNotFound; |
|
192 } |
|
193 TRACE2("ReadInt(%S) = %d",&aField,aValue); |
|
194 return KErrNone; |
|
195 } |
|
196 |
|
197 ACCESS_METHOD2(TInt, WriteInt, const TDesC& DEBUG_ONLY(aField), |
|
198 TUint32 DEBUG_ONLY(aValue)) |
|
199 { |
|
200 TRACE2("WriteInt(%S,%d)",&aField,aValue); |
|
201 return KErrNotSupported; |
|
202 } |
|
203 |
|
204 ACCESS_METHOD2(TInt, ReadDes, const TDesC& DEBUG_ONLY(aField), |
|
205 TDes8& /*aValue*/) |
|
206 { |
|
207 TRACE1("ReadDes8(%S)",&aField); |
|
208 return KErrNotFound; |
|
209 } |
|
210 |
|
211 ACCESS_METHOD2(TInt, WriteDes, const TDesC& DEBUG_ONLY(aField), |
|
212 const TDesC8& /*aValue*/) |
|
213 { |
|
214 TRACE1("WriteDes8(%S)",&aField); |
|
215 return KErrNotSupported; |
|
216 } |
|
217 |
|
218 ACCESS_METHOD2(TInt, ReadDes, const TDesC& aField, TDes16& aValue) |
|
219 { |
|
220 if (aField == KIfName) |
|
221 { |
|
222 aValue = KWinsockInterface; |
|
223 } |
|
224 else if (aField == KIfNetworks) |
|
225 { |
|
226 CWinsockProtocolFamily::ProtocolNames(aValue); |
|
227 } |
|
228 else if (aField == KIAPBearerType) |
|
229 { |
|
230 aValue = KWinsockBearerType; |
|
231 } |
|
232 else if (aField == KIAPServiceType) |
|
233 { |
|
234 aValue = KWinsockServiceType; |
|
235 } |
|
236 else if (aField == KIAPName) |
|
237 { |
|
238 aValue = KWinsockAPName; |
|
239 } |
|
240 else if (aField == KLANBearerName) |
|
241 { |
|
242 aValue = KWinsockBearerName; |
|
243 } |
|
244 else |
|
245 { |
|
246 TRACE1("ReadDes16(%S) -> KErrNotFound",&aField); |
|
247 return KErrNotFound; |
|
248 } |
|
249 TRACE2("ReadDes16(%S) = %S",&aField,&aValue); |
|
250 return KErrNone; |
|
251 } |
|
252 |
|
253 ACCESS_METHOD2(TInt, WriteDes, const TDesC& DEBUG_ONLY(aField), |
|
254 const TDesC16& /*aValue*/) |
|
255 { |
|
256 TRACE1("WriteDes16(%S)",&aField); |
|
257 return KErrNotSupported; |
|
258 } |
|
259 |
|
260 ACCESS_METHOD2(TInt, ReadBool, const TDesC& DEBUG_ONLY(aField), |
|
261 TBool& /*aValue*/) |
|
262 { |
|
263 TRACE1("ReadBool(%S)",&aField); |
|
264 return KErrNotFound; |
|
265 } |
|
266 |
|
267 ACCESS_METHOD2(TInt, WriteBool, const TDesC& DEBUG_ONLY(aField), |
|
268 TBool DEBUG_ONLY(aValue)) |
|
269 { |
|
270 TRACE2("WriteBool(%S,%d)",&aField,aValue); |
|
271 return KErrNotSupported; |
|
272 } |
|
273 |
|
274 ACCESS_METHOD1(HBufC*, ReadLongDesLC, const TDesC& DEBUG_ONLY(aField)) |
|
275 { |
|
276 TRACE1("ReadLongDesLC(%S)",&aField); |
|
277 return NULL; |
|
278 } |
|
279 |
|
280 TInt CWinsockAgent::Notification(TNifToAgentEventType DEBUG_ONLY(aEvent), |
|
281 TAny* /*aInfo*/) |
|
282 { |
|
283 TRACE1("Notification(%d)",aEvent); |
|
284 return KErrNotSupported; |
|
285 } |
|
286 |
|
287 TInt CWinsockAgent::IncomingConnectionReceived() |
|
288 { |
|
289 TRACE("IncomingConnectionReceived()"); |
|
290 return KErrNotSupported; |
|
291 } |
|
292 |
|
293 void CWinsockAgent::GetLastError(TInt& aError) |
|
294 { |
|
295 TRACE("GetLastError()"); |
|
296 aError = KErrNone; |
|
297 } |
|
298 |
|
299 TBool CWinsockAgent::IsActive() const |
|
300 { |
|
301 return ETrue; |
|
302 } |
|
303 |
|
304 TBool CWinsockAgent::IsReconnect() const |
|
305 { |
|
306 return EFalse; |
|
307 } |
|
308 |
|
309 void CWinsockAgent::SetConnectionSettingsL(const TConnectionSettings& aSettings) |
|
310 { |
|
311 TRACE("SetConnectionSettingsL()"); |
|
312 iSettings = aSettings; |
|
313 } |
|
314 |
|
315 TConnectionSettings& CWinsockAgent::ConnectionSettingsL() |
|
316 { |
|
317 TRACE("ConnectionSettingsL()"); |
|
318 return iSettings; |
|
319 } |
|
320 |
|
321 void CWinsockAgent::SetOverridesL(CStoreableOverrideSettings* /*aOverride*/) |
|
322 { |
|
323 TRACE("SetOverridesL()"); |
|
324 } |
|
325 |
|
326 CStoreableOverrideSettings* CWinsockAgent::OverridesL() |
|
327 { |
|
328 TRACE("OverridesL()"); |
|
329 User::Leave(KErrNotSupported); |
|
330 return NULL; |
|
331 } |
|
332 |
|
333 void CWinsockAgent::RequestNotificationOfServiceChangeL( |
|
334 MAgentSessionNotify* /*aSession*/) |
|
335 { |
|
336 User::Leave(KErrNotSupported); |
|
337 } |
|
338 |
|
339 void CWinsockAgent::CancelRequestNotificationOfServiceChange( |
|
340 MAgentSessionNotify* /*aSession*/) |
|
341 { |
|
342 } |
|
343 |
|
344 // Private methods |
|
345 |
|
346 void CWinsockAgent::ScheduleConnectNotification() |
|
347 { |
|
348 ASSERT(iNotify); |
|
349 if (!iConnector && iNotify) |
|
350 { |
|
351 iConnector = new CWinsockAgentCallback(this,ConnectComplete); |
|
352 } |
|
353 if (iConnector) |
|
354 { |
|
355 // Schedule asynchronous connect notification |
|
356 ASSERT(iConnector->Agent() == this); |
|
357 iConnector->InvokeLater(); |
|
358 } |
|
359 } |
|
360 |
|
361 void CWinsockAgent::CancelConnectNotification() |
|
362 { |
|
363 if (iConnector) |
|
364 { |
|
365 iConnector->Cancel(); |
|
366 } |
|
367 } |
|
368 |
|
369 void CWinsockAgent::ConnectComplete() |
|
370 { |
|
371 TRACE("firing connection notification"); |
|
372 iNotify->AgentProgress(KConnectionOpen, KErrNone); |
|
373 iNotify->ConnectComplete(KErrNone); |
|
374 } |
|
375 |
|
376 void CWinsockAgent::DisconnectComplete() |
|
377 { |
|
378 TRACE("firing disconnect notification"); |
|
379 iNotify->AgentProgress(KConnectionClosed, iDisconnectReason); |
|
380 iNotify->DisconnectComplete(); |
|
381 } |