|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 // Name : CSIPRegistrationBinding.cpp |
|
15 // Part of : Registration |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "CSIPRegistrationBinding.h" |
|
23 #include "CSIPRegistrar.h" |
|
24 #include "CSIPRegistrationBindingStore.h" |
|
25 #include "CSIPResponseUtility.h" |
|
26 #include "MRegistrationOwner.h" |
|
27 #include "csipregistrationstate.h" |
|
28 #include "sipresponse.h" |
|
29 #include "siprequest.h" |
|
30 #include "siptoheader.h" |
|
31 #include "sipaddress.h" |
|
32 #include "sipminexpiresheader.h" |
|
33 #include "sipcontactheader.h" |
|
34 #include "uricontainer.h" |
|
35 #include "SipLogs.h" |
|
36 #include "SipAssert.h" |
|
37 |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CSIPRegistrationBinding::NewLC |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CSIPRegistrationBinding* CSIPRegistrationBinding::NewLC( |
|
44 CSIPRequest* aSIPRequest, |
|
45 MSigComp& aSigComp, |
|
46 CSIPSec& aSIPSec, |
|
47 MTimerManager& aTimerMgr, |
|
48 MTransactionUser& aTransactionUser, |
|
49 CSIPRegistrationBindingStore& aBindingStore, |
|
50 MRegistrationOwner* aRegistrationOwner, |
|
51 MSIPSecUser& aSIPSecUser, |
|
52 MSIPTransportMgr& aTransportMgr, |
|
53 CURIContainer& aRemoteTarget, |
|
54 TBool aSendWithExpires, |
|
55 TBool aCacheOutboundProxyIP) |
|
56 { |
|
57 CSIPRegistrationBinding* self = new (ELeave) CSIPRegistrationBinding( |
|
58 aSigComp, aSIPSec, aTimerMgr, aTransactionUser, aBindingStore, |
|
59 aRegistrationOwner, aSIPSecUser, aTransportMgr,aSendWithExpires, |
|
60 aCacheOutboundProxyIP); |
|
61 CleanupStack::PushL(self); |
|
62 self->ConstructL(aSIPRequest, aRemoteTarget); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CSIPRegistrationBinding::CSIPRegistrationBinding |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CSIPRegistrationBinding::CSIPRegistrationBinding( |
|
71 MSigComp& aSigComp, |
|
72 CSIPSec& aSIPSec, |
|
73 MTimerManager& aTimerManager, |
|
74 MTransactionUser& aTransactionUser, |
|
75 CSIPRegistrationBindingStore& aBindingStore, |
|
76 MRegistrationOwner* aRegistrationOwner, |
|
77 MSIPSecUser& aSIPSecUser, |
|
78 MSIPTransportMgr& aTransportMgr, |
|
79 TBool aSendWithExpires, |
|
80 TBool aCacheOutboundProxyIP) |
|
81 : CSIPRegistrationBindingBase (aTransactionUser, aSigComp, aSIPSec, |
|
82 aBindingStore, aRegistrationOwner, |
|
83 aSIPSecUser, aTransportMgr,aSendWithExpires, |
|
84 aCacheOutboundProxyIP), |
|
85 iTimerMgr (aTimerManager) |
|
86 { |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CSIPRegistrationBinding::~CSIPRegistrationBinding |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CSIPRegistrationBinding::~CSIPRegistrationBinding() |
|
94 { |
|
95 iTransactionUser.ClearTransactionOwner(this); |
|
96 iTimerMgr.Stop(iTimerId); |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CSIPRegistrationBinding::IsRefresh |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 TBool CSIPRegistrationBinding::IsRefresh() const |
|
104 { |
|
105 return EFalse; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CSIPRegistrationBinding::DoRegisterL |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CSIPRegistrationBinding::DoRegisterL(TTransactionId& aTransactionId, |
|
113 CSIPRequest* aSIPRequest, |
|
114 CSIPRouteHeader* aOutboundProxy) |
|
115 { |
|
116 if (aOutboundProxy) |
|
117 { |
|
118 SetOutboundProxyL(aOutboundProxy); |
|
119 // If SendL fails the aOutboundProxy is detached from binding |
|
120 CleanupStack::PushL(TCleanupItem(DetachOutboundProxy, this)); |
|
121 } |
|
122 |
|
123 TSIPTransportParams transportParams(FillTransportParams()); |
|
124 |
|
125 if (iRegistrar) |
|
126 { |
|
127 iTransactionUser.SendL(aTransactionId, iRegistrationId, aSIPRequest, |
|
128 this, const_cast<CURIContainer&>(iRegistrar->Registrar()), |
|
129 transportParams, EFalse); |
|
130 } |
|
131 else |
|
132 { |
|
133 iTransactionUser.SendL(aTransactionId, iRegistrationId, aSIPRequest, |
|
134 this, *iRemoteTarget, transportParams, EFalse); |
|
135 } |
|
136 |
|
137 if (aOutboundProxy) |
|
138 { |
|
139 CleanupStack::Pop(); // TCleanupItem |
|
140 } |
|
141 |
|
142 if ( iCurrentState->Retrying() ) |
|
143 { |
|
144 iRetryTransactionId = aTransactionId; |
|
145 } |
|
146 |
|
147 else |
|
148 { |
|
149 iTransactionId = aTransactionId; |
|
150 } |
|
151 |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CSIPRegistrationBinding::DoUpdateL |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void CSIPRegistrationBinding::DoUpdateL(TTransactionId& aTransactionId, |
|
159 CSIPRequest* aSIPRequest) |
|
160 { |
|
161 TSIPTransportParams transportParams(FillTransportParams()); |
|
162 |
|
163 iTransactionUser.SendL(iTransactionId, iRegistrationId, |
|
164 aSIPRequest, this, const_cast<CURIContainer&>(iRegistrar->Registrar()), |
|
165 transportParams, EFalse); |
|
166 |
|
167 aTransactionId = iTransactionId; |
|
168 iTimerMgr.Stop(iTimerId); |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CSIPRegistrationBinding::DoUnregisterL |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CSIPRegistrationBinding::DoUnregisterL(TTransactionId& aTransactionId, |
|
176 CSIPRequest* aSIPRequest) |
|
177 { |
|
178 TSIPTransportParams transportParams(FillTransportParams()); |
|
179 |
|
180 iTransactionUser.SendL(iTransactionId, iRegistrationId, |
|
181 aSIPRequest, this, const_cast<CURIContainer&>(iRegistrar->Registrar()), |
|
182 transportParams, EFalse); |
|
183 |
|
184 aTransactionId = iTransactionId; |
|
185 iTimerMgr.Stop(iTimerId); |
|
186 } |
|
187 |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CSIPRegistrationBinding::ReceiveL |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CSIPRegistrationBinding::ReceiveL(TUint32 /*aIapId*/, |
|
194 TTransactionId /*aTransactionId*/, |
|
195 CSIPRequest* /*aSIPRequest*/) |
|
196 { |
|
197 // this function call is not supported |
|
198 User::Leave (KErrNotSupported); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CSIPRegistrationBinding::ReceiveL |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CSIPRegistrationBinding::ReceiveL(TTransactionId aTransactionId, |
|
206 CSIPResponse* aSIPResponse) |
|
207 { |
|
208 __SIP_ASSERT_LEAVE(aSIPResponse, KErrArgument); |
|
209 __SIP_ASSERT_LEAVE(aSIPResponse->To(), KErrArgument); |
|
210 __SIP_ASSERT_LEAVE(aTransactionId != KEmptyTransactionId, KErrArgument); |
|
211 |
|
212 // panic if transaction id is not equal to the one has sent |
|
213 __SIP_ASSERT_LEAVE(aTransactionId == iTransactionId || |
|
214 aTransactionId == iRetryTransactionId, KErrArgument); |
|
215 |
|
216 __SIP_MESSAGE_LOG("Registrations: ReceiveL", *aSIPResponse) |
|
217 |
|
218 __TEST_INVARIANT; |
|
219 |
|
220 iCurrentState->ReceiveL(iTransactionId, aSIPResponse); |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CSIPRegistrationBinding::TransactionEnded |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 TInt CSIPRegistrationBinding::TransactionEnded(TUint32 /*aIapId*/, |
|
228 TTransactionId aTransactionId, |
|
229 TInt aReason) |
|
230 { |
|
231 __SIP_ASSERT_RETURN_VALUE (aTransactionId != KEmptyTransactionId, |
|
232 KErrArgument); |
|
233 __SIP_ASSERT_RETURN_VALUE (aTransactionId == iTransactionId, |
|
234 KErrArgument); |
|
235 |
|
236 __TEST_INVARIANT; |
|
237 |
|
238 TInt res = KErrNone; |
|
239 |
|
240 if (aReason != KErrNone) |
|
241 { |
|
242 res = RemoveBinding (); |
|
243 } |
|
244 |
|
245 if(res != KErrNone) |
|
246 { |
|
247 return res; |
|
248 } |
|
249 |
|
250 return iCurrentState->TransactionEnded(aTransactionId, aReason); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CSIPRegistrationBinding::NextCSeq |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 TInt CSIPRegistrationBinding::NextCSeq(TUint& aCSeq) |
|
258 { |
|
259 if (iRegistrar) |
|
260 { |
|
261 iRegistrar->IncreaseCSeqNumber(); |
|
262 aCSeq = iRegistrar->CSeqNumber(); |
|
263 } |
|
264 else |
|
265 { |
|
266 aCSeq++; |
|
267 } |
|
268 |
|
269 return KErrNone; |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CSIPRegistrationBinding::SIPSecUser |
|
274 // From MTransactionOwner: |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 const MSIPSecUser* CSIPRegistrationBinding::SIPSecUser() const |
|
278 { |
|
279 return this; |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CSIPRegistrationBinding::TimerExpiredL |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 void CSIPRegistrationBinding::TimerExpiredL(TTimerId aTimerId, |
|
287 TAny* /*aTimerParam*/) |
|
288 { |
|
289 __SIP_ASSERT_LEAVE(iTimerId == aTimerId, KErrArgument); |
|
290 |
|
291 // if register is in registered or unregistered states, |
|
292 // binding can be removed. |
|
293 // otherwise, the registration is pending, do not delete the binding. |
|
294 if (!RegisterPending()) |
|
295 { |
|
296 ClearTransactionOwner(); |
|
297 User::LeaveIfError(RemoveBinding()); |
|
298 } |
|
299 } |
|
300 |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CSIPRegistrationBinding::StartTimerL |
|
304 // ----------------------------------------------------------------------------- |
|
305 // |
|
306 void CSIPRegistrationBinding::StartTimerL(TUint aExpiresValue) |
|
307 { |
|
308 const TUint KMilliSecondsInSecond = 1000; |
|
309 const TUint KTimerValue = (aExpiresValue * KMilliSecondsInSecond); |
|
310 iTimerId = iTimerMgr.StartL(this,KTimerValue); |
|
311 iContact->SetExpiresParameterL(aExpiresValue); |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CSIPRegistrationBinding::ClearTransactionOwner |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 void CSIPRegistrationBinding::ClearTransactionOwner ( TBool aUseRetryId ) |
|
319 { |
|
320 TTransactionId id( iTransactionId ); |
|
321 |
|
322 if ( aUseRetryId ) |
|
323 { |
|
324 // If retry-register is sent, we should clear retry transaction |
|
325 id = iRetryTransactionId; |
|
326 } |
|
327 iTransactionUser.ClearTransactionOwner( id ); |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CSIPRegistrationBinding::__DbgTestInvariant |
|
332 // ----------------------------------------------------------------------------- |
|
333 // |
|
334 void CSIPRegistrationBinding::__DbgTestInvariant() const |
|
335 { |
|
336 if (!iOwner) |
|
337 { |
|
338 User::Invariant(); |
|
339 } |
|
340 |
|
341 } |