|
1 /* |
|
2 * Copyright (c) 2005-2009 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 * Name : CSipConnection.h |
|
16 * Part of : ConnectionMgr |
|
17 * Version : SIP/4.0 |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 #ifndef __CSIPCONNECTION_H__ |
|
24 |
|
25 /** |
|
26 * @internalComponent |
|
27 */ |
|
28 #define __CSIPCONNECTION_H__ |
|
29 |
|
30 // INCLUDES |
|
31 #include "MTransportOwner.h" |
|
32 #include "MIcmpReceiver.h" |
|
33 #include "CSipConnectionMgr.h" |
|
34 #include "msipconnectioncontext.h" |
|
35 #include "MOutgoingRequestQueueContext.h" |
|
36 #include "sipnetworkobserver.h" |
|
37 #include "CNetworkManager.h" |
|
38 #include "CStateModel.h" |
|
39 #include <commsdattypesv1_1.h> |
|
40 |
|
41 #include <stringpool.h> |
|
42 |
|
43 // FORWARD DECLARATIONS |
|
44 class MTransactionFinder; |
|
45 class MSigCompController; |
|
46 class MServerTaFactory; |
|
47 class MTimerManager; |
|
48 class MSIPServerResolverObserver; |
|
49 class RSocketServ; |
|
50 class CLocalAddrResolver; |
|
51 class CTransportBase; |
|
52 class CIcmpReceiver; |
|
53 class CSIPServerResolver; |
|
54 class CSender; |
|
55 class COutgoingData; |
|
56 class CTcpResponseSender; |
|
57 class CSIPMessage; |
|
58 class CSIPViaHeader; |
|
59 class CURIContainer; |
|
60 class COwnerSettingsList; |
|
61 class CConnectionContainer; |
|
62 class CNetworkManager; |
|
63 class CStateModel; |
|
64 class CNetworkInfo; |
|
65 class CSIPNATTraversalController; |
|
66 class COutgoingRequestQueue; |
|
67 class CUri8; |
|
68 class MSIPNATBindingObserver; |
|
69 |
|
70 |
|
71 // CLASS DEFINITION |
|
72 class CSipConnection |
|
73 : public CBase, |
|
74 public MTransportOwner, |
|
75 public MSIPConnectionContext, |
|
76 public MOutgoingRequestQueueContext, |
|
77 public MIcmpErrorObserver |
|
78 { |
|
79 public: // Constructors and destructor |
|
80 |
|
81 /** |
|
82 * Constructs, adds the pointer onto the cleanup stack |
|
83 * and returns a pointer to, a new CSipConnection object; |
|
84 * leaves on failure. |
|
85 * |
|
86 * @param aFinder A reference to the MTransactionFinder object |
|
87 * @param aTaFactory A reference to the MServerTaFactory object |
|
88 * @param aTimer A reference to the MTimerManager object |
|
89 * @param aTOne T1 timervalue |
|
90 * @param aParams info about transport (iapId etc.) |
|
91 * @param aServer socket server |
|
92 * @param aSigCompHandler The handler for signaling compression |
|
93 * @param aTUNetStatusObserver Callback where the connection state |
|
94 * changes are notified |
|
95 * @param aNetworkManager Monitors network's state |
|
96 * @param aOwner Owner of the CSipConnection |
|
97 * @param aNetworkInfo Network information store |
|
98 * |
|
99 * @return CSipConnection |
|
100 */ |
|
101 static CSipConnection* |
|
102 NewLC( MTransactionFinder& aFinder, |
|
103 MServerTaFactory& aTaFactory, |
|
104 MTimerManager& aTimer, |
|
105 TUint aTOne, |
|
106 const TSIPTransportParams& aParams, |
|
107 RSocketServ& aServer, |
|
108 MSigCompController& aSigCompHandler, |
|
109 MConnectionStateObserver& aTUNetStatusObserver, |
|
110 CNetworkManager& aNetworkManager, |
|
111 MSipConnectionOwner& aOwner, |
|
112 CNetworkInfo& aNetworkInfo, |
|
113 CSIPNATTraversalController& aNATTraversal ); |
|
114 |
|
115 /// Destructor |
|
116 ~CSipConnection(); |
|
117 |
|
118 |
|
119 public: // New functions, ConnectionMgr offers through MSipConnectionMgr |
|
120 |
|
121 void SetOptL( const TSIPTransportParams& aParams, |
|
122 TUint aOptionName, |
|
123 TUint aOptionLevel, |
|
124 const TDesC8& aOption ); |
|
125 |
|
126 void SetOptL( const TSIPTransportParams& aParams, |
|
127 TUint aOptionName, |
|
128 TUint aOptionLevel, |
|
129 TInt aOption ); |
|
130 |
|
131 void SendL( const TSIPTransportParams& aParams, |
|
132 CSIPRequest& aRequest, |
|
133 TBool aForceUDP, |
|
134 const CUri8* aOutboundProxy, |
|
135 const TInetAddr& aRemoteAddr, |
|
136 TRequestStatus& aStatus ); |
|
137 |
|
138 void SendL( const TSIPTransportParams& aParams, |
|
139 CSIPResponse& aResponse, |
|
140 TTransactionId aId, |
|
141 TRequestStatus& aStatus ); |
|
142 |
|
143 TInt CancelSend( TRequestStatus &aStatus ); |
|
144 |
|
145 TInt CancelResponseSend( TTransactionId aId, TBool aCancelAlso2xxResponses ); |
|
146 |
|
147 void TcpDisconnect( const TSIPTransportParams& aParams, |
|
148 const TInetAddr& aRemoteAddress ); |
|
149 |
|
150 void FreeResources( MSIPNATBindingObserver& aSIPNATBindingObserver ); |
|
151 |
|
152 |
|
153 public: // From MSIPConnectionContext |
|
154 |
|
155 void SendToTransportL( const TSIPTransportParams& aParams, |
|
156 CSIPResponse& aResponse, |
|
157 TTransactionId aId, |
|
158 TRequestStatus &aStatus ); |
|
159 |
|
160 void SendToTransportL( const TSIPTransportParams& aParams, |
|
161 CSIPRequest& aRequest, |
|
162 TBool aForceUDP, |
|
163 const CUri8* aOutboundProxy, |
|
164 const TInetAddr& aAddr, |
|
165 TRequestStatus &aStatus ); |
|
166 |
|
167 TInt OpenConnection(); |
|
168 |
|
169 void CloseConnection(); |
|
170 |
|
171 void CreateTransportResourcesL(); |
|
172 void CreateDefaultTransportsL(); |
|
173 |
|
174 void ReleaseTransportResources( TBool aReleaseAllResources ); |
|
175 |
|
176 TBool DoTransportResourcesExist() const; |
|
177 |
|
178 void ResolveLocalAddress( TInetAddr& aAddress ); |
|
179 |
|
180 void StartMonitoringL( TInt aError ); |
|
181 |
|
182 void StopMonitoring(); |
|
183 |
|
184 TBool ContinueMonitoring( TInt aError ); |
|
185 |
|
186 TInt MonitorConnectionClosure(); |
|
187 |
|
188 void StateModelChanged( MStateModel::TState aState ); |
|
189 |
|
190 void Destroy(); |
|
191 |
|
192 TInt ConnectionType(); |
|
193 |
|
194 |
|
195 public: // From MOutgoingRequestQueueContext |
|
196 |
|
197 void ContinueSendToTransportL( const TSIPTransportParams& aParams, |
|
198 CSIPRequest& aRequest, |
|
199 TBool aForceUDP, |
|
200 const TInetAddr& aRemoteAddr, |
|
201 TUint aLocalPort, |
|
202 TUint aOrigTransport, |
|
203 TRequestStatus& aStatus, |
|
204 TBool aPublicAddrResolved ); |
|
205 |
|
206 void RequestFailed( TRequestStatus& aStatus, TInt aError ); |
|
207 |
|
208 RSocket& GetUdpSocketL( const TSIPTransportParams& aParams, |
|
209 const TInetAddr& aRemoteAddr, |
|
210 TUint& aLocalPort, |
|
211 MSocketUsagePermissionObserver* aObserver, |
|
212 TBool& aPermissionToUse ); |
|
213 |
|
214 void UdpSocketFree( const TSIPTransportParams& aParams, |
|
215 const TInetAddr& aRemoteAddr, |
|
216 TUint aLocalPort, |
|
217 MSocketUsagePermissionObserver* aObserver, |
|
218 RSocket& aSocket ); |
|
219 |
|
220 |
|
221 public: // From MTransportOwner |
|
222 |
|
223 void AddListenerL( const TSIPTransportParams& aParams, |
|
224 TUint aProtocol, |
|
225 TUint aPort ); |
|
226 |
|
227 TInt RemoveTransport( CTransportBase* aTransport ); |
|
228 |
|
229 void ReRouteL( TUint aProtocol, |
|
230 COutgoingData* aData ); |
|
231 |
|
232 void TcpConnected( const TInetAddr& aAddr ); |
|
233 |
|
234 TBool IsLocalAddr(TInetAddr& aAddr) const; |
|
235 |
|
236 void GetLocalAddrL( TInetAddr& aAddr, |
|
237 const TInetAddr* aNextHop ); |
|
238 |
|
239 TBool GetLocalIPAddr( TUint aFamily, TInetAddr& aAddr ); |
|
240 |
|
241 void FillWithMatchingAddrFamily( TInetAddr& aAddr, |
|
242 const TInetAddr* aNextHop ); |
|
243 |
|
244 TUint32 IapId() const; |
|
245 |
|
246 |
|
247 public: // New functions |
|
248 |
|
249 CSIPConnection::TState State(); |
|
250 void SystemStarted(); |
|
251 void CellularUsageAllowed(); |
|
252 void GetByURIL( const TSIPTransportParams& aParams, |
|
253 const CURIContainer& aURI, |
|
254 RPointerArray<MSIPResolvingResult>& aResult, |
|
255 MSIPServerResolverObserver* aObserver ); |
|
256 |
|
257 void CancelGetByUri( MSIPServerResolverObserver* aObserver ); |
|
258 TInt GetLocalAddress( TInetAddr& aAddr ); |
|
259 TBool Match( const TDesC8& aAddress ); |
|
260 void ResetTransportsL(); |
|
261 void CancelAllRequests( CSIPConnection::TState aReason ); |
|
262 void IcmpError( const TInetAddr& aAddress ); |
|
263 TBool Handle( TUint32 aIapId ) const; |
|
264 TInt DecreaseUserCount( const TSIPTransportParams& aParams ); |
|
265 void IncreaseUserCount(); |
|
266 void ReserveTransportL( const TSIPTransportParams& aOldTransportParams, |
|
267 const TSIPTransportParams& aTransportParams, |
|
268 TUint aLocalSendPort, |
|
269 TUint aLocalReceivePort, |
|
270 const TInetAddr& aRemoteAddr, |
|
271 TUint aRemoteSendPort ); |
|
272 void ReserveTLSTransportL( TSIPTransportParams& aTransportParams ); |
|
273 TBool RemoveReservedTransport( TUint32 aTransportId, |
|
274 MSIPTransportRemovalObserver* aRemovalObserver, |
|
275 TInt& aNumAsyncRemovals ); |
|
276 TInt ConnectionError(); |
|
277 TInt DetermineConnectionTypeL(); |
|
278 static const TInt iConnectionOffset; |
|
279 TSglQueLink iConnectionLink; |
|
280 |
|
281 private: |
|
282 |
|
283 void ConstructL(); |
|
284 CSipConnection( MTransactionFinder& aFinder, |
|
285 MServerTaFactory& aTaFactory, |
|
286 MTimerManager& aTimer, |
|
287 TUint aTOne, |
|
288 const TSIPTransportParams& aParams, |
|
289 RSocketServ& aServer, |
|
290 MSigCompController& aSigCompHandler, |
|
291 MConnectionStateObserver& aTUNetStatusObserver, |
|
292 CNetworkManager& aNetworkManager, |
|
293 MSipConnectionOwner& aOwner, |
|
294 CNetworkInfo& aNetworkInfo, |
|
295 CSIPNATTraversalController& aNATTraversal ); |
|
296 |
|
297 CTransportBase* FindTransportL( const TSIPTransportParams& aParams, |
|
298 CSIPMessage* aMessage, |
|
299 TTransactionId aId, |
|
300 TBool aIsStrict ); |
|
301 CTransportBase* FindTransportL( const TSIPTransportParams& aParams, |
|
302 CSIPMessage* aMessage, |
|
303 const TInetAddr& aRemoteAddr, |
|
304 TUint aLocalPort = 0, |
|
305 TBool aIsStrict = ETrue ); |
|
306 CTransportBase* FindTransport( const TSIPTransportParams& aParams, |
|
307 RStringF aProtocol, |
|
308 const TInetAddr& aRemoteAddr, |
|
309 TUint aLocalPort = 0, |
|
310 TBool aIsStrict = ETrue ); |
|
311 |
|
312 TBool IsListened( TInt aProtocol, TUint aPort ); |
|
313 void AddTransportL( CTransportBase* aTransport ); |
|
314 TBool IsInList( CTransportBase* aTransport ); |
|
315 void RemoveAllTransports(); |
|
316 TBool IsTransportUdp( CSIPMessage* aMessage ); |
|
317 TUint TransportProtocolL( CSIPMessage& aMessage ); |
|
318 |
|
319 void AddTcpListenerL( const TSIPTransportParams& aParams, |
|
320 TUint aPort, |
|
321 TBool aIsReserved = EFalse ); |
|
322 |
|
323 /** |
|
324 * returns pointer to created transport, ownership is not transferred |
|
325 */ |
|
326 CTransportBase* AddUdpListenerL( const TSIPTransportParams& aParams, |
|
327 TUint aPort, |
|
328 TBool aIsReserved = EFalse, |
|
329 TBool aOnlyForReceiving = EFalse ); |
|
330 |
|
331 void AddTcpListenerUserL( const TSIPTransportParams& aOldParams, |
|
332 const TSIPTransportParams& aParams, |
|
333 TUint aReceivePort ); |
|
334 |
|
335 |
|
336 void AddUdpListenerUserL( const TSIPTransportParams& aOldParams, |
|
337 const TSIPTransportParams& aParams, |
|
338 TUint aReceivePort ); |
|
339 |
|
340 void CreateConnectedTransportPointL( const TSIPTransportParams& aParams, |
|
341 CSIPMessage& aMessage, |
|
342 const TInetAddr& aAddress ); |
|
343 void CreateTcpTransportPointL( const TSIPTransportParams& aParams, |
|
344 const TInetAddr& aAddress ); |
|
345 |
|
346 void CreateTlsTransportPointL( const TSIPTransportParams& aParams, |
|
347 const TInetAddr& aAddress ); |
|
348 CSender* GetSender( const TSIPTransportParams& aParams, |
|
349 TUint aProtocol, |
|
350 const TInetAddr& aAddr ); |
|
351 TUint UpdateTransportIfNeededL( CSIPMessage& aMessage, |
|
352 const TSIPTransportParams& aParams, |
|
353 TBool aForceUDP, |
|
354 const TInetAddr& aAddr ); |
|
355 void RemoveTcpSender( CTcpResponseSender* aThis ); |
|
356 void RemoveAllTcpSender(); |
|
357 CSIPViaHeader* TopViaHeader( CSIPMessage* aMessage ); |
|
358 void SetState( MStateModel::TState aState ); |
|
359 RConnection& Connection(); |
|
360 void NotifyIcmpErrorL( const TInetAddr& aAddress ); |
|
361 TBool IsConnectionActive() const; |
|
362 void UpdateURIL( CURIContainer& aURI, |
|
363 const TInetAddr& aAddress, |
|
364 TUint aProtocol ) const; |
|
365 |
|
366 private: // Data |
|
367 |
|
368 MTransactionFinder& iFinder; |
|
369 MServerTaFactory& iTaFactory; |
|
370 MConnectionStateObserver& iTUNetStatusObserver; |
|
371 CLocalAddrResolver* iLocalAddrResolver; |
|
372 |
|
373 MSigCompController& iSigCompHandler; |
|
374 |
|
375 RSocketServ& iServer; |
|
376 TSglQue<CTransportBase> iList; |
|
377 TSglQueIter<CTransportBase> iListIter; |
|
378 TSglQue<CTcpResponseSender> iTcpSenderList; |
|
379 TSglQueIter<CTcpResponseSender> iTcpSenderListIter; |
|
380 TUint iTOne; |
|
381 CIcmpReceiver* iIcmpReceiver; |
|
382 CSIPServerResolver* iServerResolver; |
|
383 TInt iUserCount; |
|
384 |
|
385 CNetworkManager& iNetworkManager; |
|
386 CConnectionContainer* iConnection; |
|
387 CStateModel* iStateModel; |
|
388 MTimerManager& iTimer; |
|
389 MSipConnectionOwner& iOwner; |
|
390 TUint32 iIapId; |
|
391 CSIPConnection::TState iState; |
|
392 |
|
393 COwnerSettingsList* iSettingsList; |
|
394 |
|
395 COutgoingRequestQueue* iRequestQueue; |
|
396 |
|
397 CNetworkInfo& iNetworkInfo; |
|
398 |
|
399 CSIPNATTraversalController& iNATTraversal; |
|
400 |
|
401 TBool iWaitingForDataUsage; |
|
402 |
|
403 friend class CTcpResponseSender; |
|
404 |
|
405 private: // For testing purposes |
|
406 #ifdef CPPUNIT_TEST |
|
407 friend class CSipConnectionTest; |
|
408 friend class CSipConnectionMgrTest; |
|
409 friend class CTcpResponseHandlerTest; |
|
410 #endif |
|
411 }; |
|
412 |
|
413 |
|
414 #endif // end of __CSipConnection_H__ |