|
1 /* |
|
2 * Copyright (c) 2006-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 : InviteUAC.h |
|
16 * Part of : TransactionUser |
|
17 * Version : SIP/5.0 |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 /** |
|
25 @internalComponent |
|
26 */ |
|
27 |
|
28 #ifndef INVITEUAC_H |
|
29 #define INVITEUAC_H |
|
30 |
|
31 // INCLUDES |
|
32 #include "UserAgentClient.h" |
|
33 |
|
34 // FORWARD DECLARATIONS |
|
35 class CTimerStopUA; |
|
36 class CTimerAsyncSIPSec; |
|
37 |
|
38 |
|
39 // CLASS DECLARATION |
|
40 |
|
41 class CInviteUAC : public CUserAgentClient |
|
42 { |
|
43 public: // Constructor and destructor |
|
44 |
|
45 /** |
|
46 * Creates a new CInviteUAC instance. |
|
47 * |
|
48 * @param aParams UA parameters |
|
49 * @param aConnectionMgr ConnectionMgr used for sending |
|
50 * @param aResolver For resolving URI |
|
51 * @param aSIPSec SIP security subsystem |
|
52 * @param aCSeqNumber CSeq value to put into INVITE if CSeq was not filled |
|
53 * by upper layers. |
|
54 * @param aIsPrivateAddress ETrue if the local address is in IPv4 private |
|
55 * address space. EFalse otherwise. |
|
56 * @param aAckSenderState The starting state of the FSM of InviteUACs that |
|
57 * send the additional ACK requests to network. |
|
58 * @return New object, ownership is transferred. |
|
59 */ |
|
60 static CInviteUAC* NewL(CUserAgentCreateParams& aParams, |
|
61 MSipConnectionMgr& aConnectionMgr, |
|
62 MSipUriResolver& aResolver, |
|
63 CSIPSec& aSIPSec, |
|
64 TUint32 aCSeqNumber, |
|
65 TBool aIsPrivateAddress, |
|
66 CUserAgentState* aAckSenderState); |
|
67 |
|
68 ~CInviteUAC(); |
|
69 |
|
70 public: // From CUserAgentClient |
|
71 |
|
72 void ReceiveResponseL(CSIPResponse* aResp, |
|
73 const CUserAgentState& aResolve, |
|
74 const CUserAgentState& aWaitResponse, |
|
75 const CUserAgentState& aWaitAckFromApp, |
|
76 const CUserAgentState& aWaitTransactionToEnd); |
|
77 |
|
78 /** |
|
79 * A new CTransmitter instance is created for InviteUAC and it's new |
|
80 * transaction. Ownership of the current CTransmitter is passed to the old |
|
81 * transaction. Two separate CTransmitter instances are needed to allow |
|
82 * both the old and new CInviteClientTransaction to send messages |
|
83 * simultaneously. |
|
84 * |
|
85 * @param aNewTransactionId TransactionId that is given to the old |
|
86 * transaction. |
|
87 */ |
|
88 void PrepareTxForNewRequestL(TTransactionId& aNewTransactionId); |
|
89 |
|
90 private: // From CUserAgentClient |
|
91 |
|
92 void CreateTransactionL(); |
|
93 |
|
94 public: // From CUserAgent |
|
95 |
|
96 void ClearTransactionOwner(); |
|
97 |
|
98 void DeleteTimer(const CUserAgentTimer& aTimer); |
|
99 |
|
100 TBool IsInviteUAC() const; |
|
101 |
|
102 TBool IsSubInviteUAC() const; |
|
103 |
|
104 public: // New functions |
|
105 |
|
106 /** |
|
107 * Checks if the InviteUAC has been canceled. |
|
108 * |
|
109 * @return ETrue: InviteUAC has been canceled, EFalse: otherwise |
|
110 */ |
|
111 TBool IsCanceled() const; |
|
112 |
|
113 /** |
|
114 * Start a timer to cause the processing of a response to go asynchronous, |
|
115 * also now that SIPSec processed the response synchronously. |
|
116 */ |
|
117 void StartSIPSecTimerL(); |
|
118 |
|
119 /** |
|
120 * Send ACK request. |
|
121 * |
|
122 * @param aAck ACK request. Parameter aDeleteRequest determines whether the |
|
123 * ownership of aAck is transferred. |
|
124 * @param aObserver IN: Callback to upper layer. |
|
125 * @param aParams Transport parameters to be used for sending the ACK |
|
126 * @param aRegisterId Identifies the registration whose outbound proxy may |
|
127 * be used. |
|
128 * @param aRemoteTarget Remote target of the ACK |
|
129 * @param aDeleteRequest If ETrue, ownership of aAck is transferred. |
|
130 * @param aBranch The branch value to put into the ACK. If this is an empty |
|
131 * string, a new branch is generated. |
|
132 */ |
|
133 void SendAckL(CSIPRequest* aAck, |
|
134 MTransactionOwner& aObserver, |
|
135 const TSIPTransportParams& aParams, |
|
136 TRegistrationId aRegisterId, |
|
137 const CURIContainer& aRemoteTarget, |
|
138 TBool aDeleteRequest, |
|
139 RStringF aBranch); |
|
140 |
|
141 /** |
|
142 * The first ACK to a 2xx is sent. |
|
143 * |
|
144 * @param aAck ACK request. Parameter aDeleteRequest determines whether the |
|
145 * ownership of aAck is transferred. |
|
146 * @param aObserver IN: Callback to upper layer. |
|
147 * @param aParams Transport parameters to be used for sending the ACK |
|
148 * @param aRegisterId Identifies the registration whose outbound proxy may |
|
149 * be used. |
|
150 * @param aRemoteTarget Remote target of the ACK |
|
151 * @param aDeleteRequest If ETrue, ownership of aAck is transferred. |
|
152 * @param aBranch The branch value to put into the ACK. If this is an empty |
|
153 * string, a new branch is generated. |
|
154 */ |
|
155 void SendFirstAckL(CSIPRequest* aAck, |
|
156 MTransactionOwner& aObserver, |
|
157 const TSIPTransportParams& aParams, |
|
158 TRegistrationId aRegisterId, |
|
159 const CURIContainer& aRemoteTarget, |
|
160 TBool aDeleteRequest, |
|
161 RStringF aBranch); |
|
162 |
|
163 /** |
|
164 * The Invite client transaction is canceled. If InviteUAC doesn't receive |
|
165 * a final response, it ends with a reason KErrCancel. |
|
166 */ |
|
167 void CancelInvite(); |
|
168 |
|
169 /** |
|
170 * Route headers are copied from INVITE to the CANCEL. |
|
171 * |
|
172 * @pre iOutgoingMsg != NULL |
|
173 * |
|
174 * @param aCancel IN/OUT: CANCEL request |
|
175 */ |
|
176 void CopyRouteHeadersToCancelL(CSIPRequest& aCancel); |
|
177 |
|
178 void HandleIcmpErrorL(const TInetAddr& aAddress, |
|
179 const CUserAgentState& aResolveAckAddress, |
|
180 const CUserAgentState& aWaitResponse); |
|
181 |
|
182 /** |
|
183 * Checks that the ACK contains all the necessary information for TU to |
|
184 * send it. If it doesn't function leaves. |
|
185 * |
|
186 * @param aAck ACK message |
|
187 */ |
|
188 void CheckAckL(CSIPRequest& aAck) const; |
|
189 |
|
190 /** |
|
191 * Fills the ACK. |
|
192 * |
|
193 * @param aAck ACK request |
|
194 * @param aBranch The branch value to put into the ACK. If this is an empty |
|
195 * string, a new branch is generated. |
|
196 */ |
|
197 void FillAckL(CSIPRequest& aAck, RStringF aBranch); |
|
198 |
|
199 /** |
|
200 * The remote address for ACK has been resolved. UserAgent will send the |
|
201 * ACK to the first address received from ServerResolver. |
|
202 */ |
|
203 void AckAddressResolvedL(); |
|
204 |
|
205 /** |
|
206 * Send another ACK, after at least one ACK has already been sent. |
|
207 * UAC has to resolve the remote address for every ACK, so it creates a |
|
208 * CAckHandler object for resolving and sending all the subsequent ACKs |
|
209 * from the upper layer, after the first ACK. UAC handles the first ACK |
|
210 * from upper layer by itself. |
|
211 * |
|
212 * @param aAck ACK message |
|
213 * @param aObserver IN: Callback to upper layer. |
|
214 * @param aParams Transport parameters to be used for sending the ACK |
|
215 * @param aRegisterId Registration id to get outbound proxy |
|
216 * @param aRemoteTarget Remote target |
|
217 * @param aDeleteRequest If ETrue, CAckHandler will delete aAck when it |
|
218 * ends. If EFalse, aAck is freed by the upper layer. |
|
219 */ |
|
220 void SendAdditionalAckL(CSIPRequest* aAck, |
|
221 MTransactionOwner& aObserver, |
|
222 const TSIPTransportParams& aParams, |
|
223 TRegistrationId aRegisterId, |
|
224 const CURIContainer& aRemoteTarget, |
|
225 TBool aDeleteRequest); |
|
226 |
|
227 /** |
|
228 * UAC receives another 2xx, which is either a retransmission, or 2xx from |
|
229 * another endpoint with a different To-tag. In either case, the 2xx is |
|
230 * passed to upper layer which will (re)send the ACK. |
|
231 * |
|
232 * @pre aResp != NULL |
|
233 * |
|
234 * @param aResp 2xx response, ownership is transferred. |
|
235 */ |
|
236 void HandleAdditional2xxL(CSIPResponse* aResp); |
|
237 |
|
238 static CInviteUAC& Ptr(CUserAgent& aUserAgent); |
|
239 |
|
240 void SetSipSecError(TInt aErr); |
|
241 |
|
242 private: |
|
243 |
|
244 CInviteUAC(CUserAgentCreateParams& aParams, |
|
245 MSipConnectionMgr& aConnectionMgr, |
|
246 MSipUriResolver& aResolver, |
|
247 CSIPSec& aSIPSec, |
|
248 TUint32 aCSeqNumber, |
|
249 TBool aIsPrivateAddress, |
|
250 CUserAgentState* aAckSenderState); |
|
251 |
|
252 /** |
|
253 * Stop and delete the CTransaction object. |
|
254 * |
|
255 * @pre iTransaction != NULL |
|
256 * @pre iDeleteThisTransaction == NULL |
|
257 * @post iTransaction == NULL |
|
258 */ |
|
259 void StopTransaction(); |
|
260 |
|
261 void StopTimerUaTimeout(); |
|
262 |
|
263 void StopTimerSIPSec(); |
|
264 |
|
265 void CancelAllTimers(); |
|
266 |
|
267 /** |
|
268 * Selects the branch value to be used for ACK. |
|
269 * |
|
270 * @param aObserver IN: Callback to upper layer. |
|
271 * @return Branch value to use, or an empty descriptor if a new branch will |
|
272 * be generated. |
|
273 */ |
|
274 RStringF SelectBranchToUse(MTransactionOwner& aObserver) const; |
|
275 |
|
276 RStringF UsedBranch(MTransactionOwner& aObserver) const; |
|
277 |
|
278 private: // Data |
|
279 |
|
280 //Used to create another CTransmitter or clone CInviteUAC. |
|
281 MSipConnectionMgr& iConnectionMgr; |
|
282 |
|
283 //This timer is started when the first 2xx is received. When the timer |
|
284 //expires, UA stops. Owned. |
|
285 CTimerStopUA* iTimerWait2xxRetransmissions; |
|
286 |
|
287 //Used to handle responses asynchronously even if SIPSec processed it |
|
288 //synchronously. Owned. |
|
289 CTimerAsyncSIPSec* iSIPSecTimer; |
|
290 |
|
291 //Tells if the local address is in IPv4 private address space |
|
292 TBool iIsPrivateAddress; |
|
293 |
|
294 //Initial state of InviteUACs that send the additional ACKs ("sub UACs"). |
|
295 //For "sub UAC", the iAckSenderState is NULL. Not owned. |
|
296 CUserAgentState* iAckSenderState; |
|
297 |
|
298 //For handling ACKs after the first ACK, CInviteUAC creates a "sub UAC" for |
|
299 //handling every subsequent ACK. A "sub UAC" resolves the remote address |
|
300 //for ACK and sends it to network. "sub UACs" are owned by the main |
|
301 //CInviteUAC who created them. "sub UACs" don't receive messages from |
|
302 //ConnectionMgr, as they are not stored in CTransactionStore. |
|
303 RPointerArray<CInviteUAC> iAckSenders; |
|
304 |
|
305 //Remembers the callback that was used when the first ACK to a 2xx was |
|
306 //sent. Used to check if a subsequent ACK is a retransmission. Not owned. |
|
307 //UAC still updates iObserver each time an ACK is sent, and uses it for |
|
308 //calling TransactionEnded. |
|
309 MTransactionOwner* iObserverForFirstAck; |
|
310 |
|
311 //Indicates is the INVITE client transaction has been canceled. |
|
312 //If this flag is ETrue and InviteUAC ends because of timeout, the reason |
|
313 //is converted to KErrCancel before passing it to upper layer. |
|
314 TBool iCanceled; |
|
315 |
|
316 //Used only to store a detached INVITE client transaction that couldn't be |
|
317 //given to DeleteMgr due to lack of memory. Owned. |
|
318 CTransactionBase* iDeleteThisTransaction; |
|
319 |
|
320 private: // For testing purposes |
|
321 |
|
322 #ifdef CPPUNIT_TEST |
|
323 friend class CInviteUAC_Start_Test; |
|
324 friend class CInviteUAC_ResolveAddress_Test; |
|
325 friend class CInviteUAC_WaitResponse_Test; |
|
326 friend class CInviteUAC_WaitAckFromApp_Test; |
|
327 friend class CInviteUAC_ResolveAckAddress_Test; |
|
328 friend class CInviteUAC_SendingAck_Test; |
|
329 friend class CUserAgentClient_Test; |
|
330 friend class CTransactionUser_Test; |
|
331 #endif |
|
332 |
|
333 void __DbgTestInvariant() const; |
|
334 |
|
335 }; |
|
336 |
|
337 #endif // end of INVITEUAC_H |
|
338 |
|
339 // End of File |