|
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 : sipietfprofilecontext.cpp |
|
15 // Part of : sip ietf agent |
|
16 // implementation |
|
17 // Version : 1.0 |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include "sipietfprofilecontext.h" |
|
25 #include "sipprflstatebase.h" |
|
26 #include "sipconcreteprofile.h" |
|
27 #include "sipietfprofileagent.h" |
|
28 #include "sipregistrationbinding.h" |
|
29 #include "sipclienttransaction.h" |
|
30 #include "siprouteheader.h" |
|
31 #include "sipgendefs.h" |
|
32 #include "siprefresh.h" |
|
33 #include "sipmessagebuilder.h" |
|
34 #include "sipaddress.h" |
|
35 #include "siptoheader.h" |
|
36 #include "siprouteheader.h" |
|
37 #include "sipmessageelements.h" |
|
38 #include "sipresponseelements.h" |
|
39 #include "sipsecurityclientheader.h" |
|
40 #include "sipconnection.h" |
|
41 #include "SipProfileLog.h" |
|
42 #include "sipstrings.h" |
|
43 #include "sipstrconsts.h" |
|
44 #include "siperr.h" |
|
45 #include "sipcodecerr.h" |
|
46 #include "sipcontactheader.h" |
|
47 #include <sipprofile.h> |
|
48 #include <bamdesca.h> |
|
49 #include <e32math.h> |
|
50 #include <uri8.h> |
|
51 #include <uriutils.h> |
|
52 |
|
53 _LIT8(KNATTraversalRequiredDes, "nat_traversal_required"); |
|
54 _LIT8(KSIPTls, "tls"); |
|
55 _LIT8(KTransportUdpParam, "transport=udp"); |
|
56 _LIT8(KTransportTcpParam, "transport=tcp"); |
|
57 _LIT8(KTransportTlsParam, "transport=tls"); |
|
58 |
|
59 const TUint KMaxRandomLimit = 50; |
|
60 const TUint KBaseTimeInSec = 30; |
|
61 const TUint KWaitTimeCoefficient = 2; |
|
62 const TUint KRandomDivider = 100; |
|
63 const TUint KMaxRetryForOneAddress = 9; |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CSIPIetfProfileContext::NewLC |
|
67 // (other items were commented in a header). |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CSIPIetfProfileContext* CSIPIetfProfileContext::NewLC( |
|
71 CSIP& aSIP, |
|
72 CSIPIetfConnectionContext& aConnection, |
|
73 MSIPProfileAgentObserver& aObserver, |
|
74 CSIPPrflStateBase& aInitState, |
|
75 CSIPConcreteProfile& aProfile, |
|
76 CDeltaTimer& aDeltaTimer, |
|
77 CSipProfileAgentConfigExtension& aConfigExtension) |
|
78 { |
|
79 CSIPIetfProfileContext* self = new (ELeave) CSIPIetfProfileContext(aSIP, |
|
80 aConnection, aObserver, aInitState, aProfile, aDeltaTimer,aConfigExtension); |
|
81 CleanupStack::PushL(self); |
|
82 self->ConstructL(); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CSIPIetfProfileContext::NewL |
|
88 // (other items were commented in a header). |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CSIPIetfProfileContext* CSIPIetfProfileContext::NewL( |
|
92 CSIP& aSIP, |
|
93 CSIPIetfConnectionContext& aConnection, |
|
94 MSIPProfileAgentObserver& aObserver, |
|
95 CSIPPrflStateBase& aInitState, |
|
96 CSIPConcreteProfile& aProfile, |
|
97 CDeltaTimer& aDeltaTimer, |
|
98 CSipProfileAgentConfigExtension& aConfigExtension) |
|
99 { |
|
100 CSIPIetfProfileContext* self = CSIPIetfProfileContext::NewLC( |
|
101 aSIP, aConnection, aObserver, aInitState, aProfile, aDeltaTimer,aConfigExtension); |
|
102 CleanupStack::Pop(); |
|
103 return self; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CSIPIetfProfileContext::CSIPIetfProfileContext |
|
108 // (other items were commented in a header). |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 CSIPIetfProfileContext::CSIPIetfProfileContext( |
|
112 CSIP& aSIP, |
|
113 CSIPIetfConnectionContext& aConnection, |
|
114 MSIPProfileAgentObserver& aObserver, |
|
115 CSIPPrflStateBase& aInitState, |
|
116 CSIPConcreteProfile& aProfile, |
|
117 CDeltaTimer& aDeltaTimer, |
|
118 CSipProfileAgentConfigExtension& aConfigExtension) |
|
119 : CSIPProfileContextBase(aSIP, |
|
120 *(aConnection.Connection()), |
|
121 aObserver, |
|
122 aInitState, |
|
123 aProfile, |
|
124 aDeltaTimer), |
|
125 iConnectionContext(aConnection), |
|
126 iRetryTimerUse(EFalse), |
|
127 iConfigExtension(aConfigExtension) |
|
128 { |
|
129 iRandomSeed = 0; |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CSIPIetfProfileContext::ConstructL |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CSIPIetfProfileContext::ConstructL() |
|
137 { |
|
138 iStrNATTraversalRequired = |
|
139 SIPStrings::Pool().OpenFStringL(KNATTraversalRequiredDes); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CSIPIetfProfileContext::~CSIPIetfProfileContext |
|
144 // (other items were commented in a header). |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 CSIPIetfProfileContext::~CSIPIetfProfileContext() |
|
148 { |
|
149 iStrNATTraversalRequired.Close(); |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CSIPIetfProfileContext::DestroyRegistration() |
|
154 // (other items were commented in a header). |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CSIPIetfProfileContext::DestroyRegistration() |
|
158 { |
|
159 PROFILE_DEBUG3("SIPIetfProfileContext::DestroyRegistration", ProfileId()) |
|
160 delete iRegistration; |
|
161 iRegistration = 0; |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CSIPIetfProfileContext::CreateRegistrationL |
|
166 // (other items were commented in a header). |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CSIPIetfProfileContext::CreateRegistrationL() |
|
170 { |
|
171 ASSERT(iProfile); |
|
172 RStringF transport(SIPStrings::StringF(SipStrConsts::EEmpty)); |
|
173 CleanupClosePushL(transport); |
|
174 CSIPRouteHeader* proxy = 0; |
|
175 CUri8* remoteUri = 0; |
|
176 CSIPRefresh* refresh = CSIPRefresh::NewLC(); |
|
177 CSIPToHeader* to = SIPMessageBuilder::CreateToLC(iProfile->AOR()); |
|
178 to->SetParamL(iStrNATTraversalRequired); |
|
179 TUint pops = 2; //initial amount to pop from CleanupStack |
|
180 |
|
181 const TDesC8& proxyAddr = ProxyAddressL(); |
|
182 HBufC8* sipsproxy = NULL; |
|
183 if(IsAddressSIPSURIL(iProfile->AOR()) && proxyAddr.Length() > 0) |
|
184 { |
|
185 if (!IsProxyResolvingEnabled()) |
|
186 { |
|
187 __ASSERT_ALWAYS (IsAddressSIPSURIL(proxyAddr), |
|
188 User::Leave(KErrArgument)); |
|
189 } |
|
190 else |
|
191 { |
|
192 sipsproxy = SetAddressToSIPSURIL(proxyAddr); |
|
193 CleanupStack::PushL(sipsproxy); |
|
194 pops++; |
|
195 } |
|
196 __ASSERT_ALWAYS (!iProfile->IsSecurityNegotiationEnabled(), |
|
197 User::Leave(KErrArgument)); |
|
198 } |
|
199 |
|
200 if (!sipsproxy) |
|
201 { |
|
202 sipsproxy = proxyAddr.AllocLC(); |
|
203 pops++; |
|
204 } |
|
205 |
|
206 if (sipsproxy->Length()) //there's an outbound proxy defined |
|
207 { |
|
208 (iProfile->IsSigCompEnabled())? |
|
209 proxy = SIPMessageBuilder::CreateRouteLC(*sipsproxy, ETrue): |
|
210 proxy = SIPMessageBuilder::CreateRouteLC(*sipsproxy); |
|
211 pops++; |
|
212 RStringF proxyTransport = TransportProtocol(proxy->SIPAddress().Uri8()); |
|
213 if (proxyTransport.DesC().Length() > 0) |
|
214 { |
|
215 transport = proxyTransport.Copy(); |
|
216 } |
|
217 } |
|
218 |
|
219 if (iProfile->Server(KSIPRegistrar).Length()) //there's a registrar defined |
|
220 { |
|
221 TUriParser8 parser; |
|
222 User::LeaveIfError(parser.Parse(iProfile->Server(KSIPRegistrar))); |
|
223 remoteUri = CUri8::NewLC(parser); |
|
224 pops++; |
|
225 if (!proxy) |
|
226 { |
|
227 RStringF registrarTransport = TransportProtocol(*remoteUri); |
|
228 if (registrarTransport.DesC().Length() > 0) |
|
229 { |
|
230 transport = registrarTransport.Copy(); |
|
231 } |
|
232 } |
|
233 } |
|
234 |
|
235 TBool sigcomp = iProfile->IsSigCompEnabled(); |
|
236 |
|
237 const TDesC8* user = NULL; |
|
238 User::LeaveIfError( |
|
239 iProfile->ExtensionParameter(KSIPContactHeaderUser,user)); |
|
240 |
|
241 CSIPContactHeader* contact = |
|
242 SIPMessageBuilder::CreateContactLC(*user, |
|
243 iConfigExtension.ExpiryValueL(TSIPProfileTypeInfo::EInternet, |
|
244 CSipProfileAgentConfigExtension::EProfileRegistrationValue), |
|
245 iProfile->ContactHeaderParams(), |
|
246 transport, sigcomp); |
|
247 pops++; |
|
248 |
|
249 if (IsAddressSIPSURIL(iProfile->AOR())) |
|
250 { |
|
251 CUri8* contactUriClone = |
|
252 CUri8::NewLC(contact->SIPAddress()->Uri8().Uri()); |
|
253 contactUriClone->SetComponentL( |
|
254 SIPStrings::StringF(SipStrConsts::ESips).DesC(),EUriScheme); |
|
255 contactUriClone->SetComponentL(*user,EUriUserinfo); |
|
256 contact->SIPAddress()->SetUri8L(contactUriClone); |
|
257 CleanupStack::Pop(contactUriClone); |
|
258 } |
|
259 |
|
260 iRegistration = CSIPRegistrationBinding::NewL(iConnection, to, contact, |
|
261 refresh, proxy, remoteUri); |
|
262 CleanupStack::Pop(pops); |
|
263 delete sipsproxy; |
|
264 CleanupStack::PopAndDestroy(1); // transport |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // CSIPIetfProfileContext::CreateMsgElementsLC() |
|
269 // (other items were commented in a header). |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 CSIPMessageElements* CSIPIetfProfileContext::CreateMsgElementsLC() |
|
273 { |
|
274 ASSERT(iProfile); |
|
275 |
|
276 CSIPMessageElements* elements = CSIPMessageElements::NewLC(); |
|
277 |
|
278 RPointerArray<CSIPHeaderBase> headers; |
|
279 CSIPHeaderBase::PushLC(&headers); |
|
280 if (SetTlsToSecurityClientL()) |
|
281 { |
|
282 CSIPSecurityClientHeader* sclient = |
|
283 CSIPSecurityClientHeader::NewLC(KSIPTls); |
|
284 headers.AppendL(sclient); |
|
285 CleanupStack::Pop(sclient); |
|
286 } |
|
287 |
|
288 if (iProfile->IsSecurityNegotiationEnabled()) |
|
289 { |
|
290 CSIPSecurityClientHeader* sclient = |
|
291 CSIPSecurityClientHeader::NewLC(KSIPdigest); |
|
292 headers.AppendL(sclient); |
|
293 CleanupStack::Pop(sclient); |
|
294 } |
|
295 |
|
296 TInt sipHeaderCount = iProfile->SIPHeaders().MdcaCount(); |
|
297 for (TInt i=0; i < sipHeaderCount; i++) |
|
298 { |
|
299 TPtrC8 headerDes(iProfile->SIPHeaders().MdcaPoint(i)); |
|
300 CSIPHeaderBase* header = SIPMessageBuilder::CreateHeaderLC(headerDes); |
|
301 headers.AppendL(header); |
|
302 CleanupStack::Pop(header); |
|
303 } |
|
304 |
|
305 elements->SetUserHeadersL(headers); // // An empty array is also allowed |
|
306 CleanupStack::Pop(1); // headers |
|
307 |
|
308 return elements; |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CSIPIetfProfileContext::CreateDeRegisterElementsL() |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 CSIPMessageElements* CSIPIetfProfileContext::CreateDeRegisterElementsL() |
|
316 { |
|
317 return NULL; |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CSIPIetfProfileContext::UpdateContactHeaderParamsL |
|
322 // (other items were commented in a header). |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 void CSIPIetfProfileContext::UpdateContactHeaderParamsL( |
|
326 CSIPConcreteProfile& aNewProfile) |
|
327 { |
|
328 CSIPContactHeader& contact = Registration()->ContactHeader(); |
|
329 TPtrC8 paramName; |
|
330 TPtrC8 paramValue; |
|
331 |
|
332 for (TInt i = Profile()->ContactHeaderParams().MdcaCount()-1;i >= 0; i--) |
|
333 { |
|
334 TPtrC8 param(Profile()->ContactHeaderParams().MdcaPoint(i)); |
|
335 SIPMessageBuilder::ParseParamL(param,paramName,paramValue); |
|
336 RStringF name = SIPStrings::Pool().OpenFStringL(paramName); |
|
337 CleanupClosePushL(name); |
|
338 contact.DeleteParam(name); |
|
339 CleanupStack::PopAndDestroy(1); // name |
|
340 } |
|
341 |
|
342 for (TInt i = 0; &(aNewProfile.ContactHeaderParams()) && |
|
343 (i < aNewProfile.ContactHeaderParams().MdcaCount()); i++) |
|
344 { |
|
345 TPtrC8 param(aNewProfile.ContactHeaderParams().MdcaPoint(i)); |
|
346 TBool hasValue = |
|
347 SIPMessageBuilder::ParseParamL(param,paramName,paramValue); |
|
348 RStringF name = SIPStrings::Pool().OpenFStringL(paramName); |
|
349 CleanupClosePushL(name); |
|
350 if (hasValue) |
|
351 { |
|
352 RStringF value = SIPStrings::Pool().OpenFStringL(paramValue); |
|
353 CleanupClosePushL(value); |
|
354 contact.SetParamL(name,value); |
|
355 CleanupStack::PopAndDestroy(1); // value |
|
356 } |
|
357 else |
|
358 { |
|
359 contact.SetParamL(name); |
|
360 } |
|
361 CleanupStack::PopAndDestroy(1); // name |
|
362 } |
|
363 |
|
364 CSIPMessageElements* elements = CreateMsgElementsForUpdateLC(aNewProfile); |
|
365 SetTransaction(Registration()->UpdateL( |
|
366 iConfigExtension.ExpiryValueL(TSIPProfileTypeInfo::EInternet, |
|
367 CSipProfileAgentConfigExtension::EProfileRegistrationValue), |
|
368 elements)); |
|
369 CleanupStack::Pop(elements); |
|
370 } |
|
371 |
|
372 // ----------------------------------------------------------------------------- |
|
373 // CSIPIetfProfileContext::SetRegisteredAORsL() |
|
374 // ----------------------------------------------------------------------------- |
|
375 // |
|
376 void CSIPIetfProfileContext::SetRegisteredAORsL() |
|
377 { |
|
378 if (iProfile) |
|
379 { |
|
380 CDesC8ArrayFlat* array = new(ELeave)CDesC8ArrayFlat(1); |
|
381 CleanupStack::PushL(array); |
|
382 array->AppendL(iProfile->AOR()); |
|
383 iProfile->SetRegisteredAORsL(*array); |
|
384 CleanupStack::PopAndDestroy(array); |
|
385 if (iRegistration && iRegistration->RegisteredContact()) |
|
386 { |
|
387 HBufC8* contact = |
|
388 iRegistration->RegisteredContact()->ToTextValueLC(); |
|
389 iProfile->SetExtensionParameterL(KSIPRegisteredContact,*contact); |
|
390 CleanupStack::PopAndDestroy(contact); |
|
391 } |
|
392 } |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // CSIPIetfProfileContext::ResolveProxyL |
|
397 // ----------------------------------------------------------------------------- |
|
398 // |
|
399 void CSIPIetfProfileContext::ResolveProxyL() |
|
400 { |
|
401 iConnectionContext.ResolveL(); |
|
402 } |
|
403 |
|
404 // ----------------------------------------------------------------------------- |
|
405 // CSIPIetfProfileContext::CancelProxyResolving |
|
406 // ----------------------------------------------------------------------------- |
|
407 // |
|
408 void CSIPIetfProfileContext::CancelProxyResolving() |
|
409 { |
|
410 iConnectionContext.CleanProxyResolving(); |
|
411 } |
|
412 |
|
413 // ----------------------------------------------------------------------------- |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // CSIPIetfProfileContext::RetryAfterTimer |
|
417 // (other items were commented in a header). |
|
418 // ----------------------------------------------------------------------------- |
|
419 // |
|
420 TBool CSIPIetfProfileContext::RetryAfterTimer() |
|
421 { |
|
422 return ( iRetryCounterSum == 0 && iRetryTimerUse ); |
|
423 } |
|
424 |
|
425 // ----------------------------------------------------------------------------- |
|
426 // CSIPIetfProfileContext::RetryRegister |
|
427 // (other items were commented in a header). |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 TBool CSIPIetfProfileContext::RetryRegister( |
|
431 CSIPClientTransaction* /*aTransaction*/, |
|
432 TInt aError ) |
|
433 { |
|
434 PROFILE_DEBUG4("CSIPIetfProfileContext::RetryRegister", |
|
435 aError, iRetryCounterSum) |
|
436 |
|
437 TBool retry = EFalse; |
|
438 |
|
439 if (iProfile && |
|
440 AgentObserver().ProceedRegistration(*iProfile, aError) && |
|
441 (CurrentState() == MSIPProfileContext::ERegistrationInProgress || |
|
442 CurrentState() == MSIPProfileContext::ERegistered) && |
|
443 (aError == KErrSIPOutboundProxyNotResponding || |
|
444 aError == KErrSIPResolvingFailure || |
|
445 aError == KErrTimedOut || |
|
446 aError == KErrSIPTransportFailure || |
|
447 aError == KErrSIPICMPFailure && |
|
448 iConnection.State() != CSIPConnection::ESuspended)) |
|
449 { |
|
450 if ( iRetryCounterSum + 1 < KMaxRetryForOneAddress && |
|
451 iRetryCounter < KMaxRetryForOneAddress ) |
|
452 { |
|
453 retry = ETrue; |
|
454 } |
|
455 else |
|
456 { |
|
457 if (iRetryCounterSum < KMaxRetryForOneAddress && |
|
458 iRetryCounter + 1 >= KMaxRetryForOneAddress || |
|
459 iRetryCounter >= KMaxRetryForOneAddress) |
|
460 { |
|
461 iRetryCounter = 0; |
|
462 retry = RetryPossible(aError); |
|
463 } |
|
464 else |
|
465 { |
|
466 retry = ETrue; |
|
467 } |
|
468 } |
|
469 iRetryTimerUse = retry; |
|
470 SetRetryPossible(retry); |
|
471 } |
|
472 else |
|
473 { |
|
474 iRetryCounter = 0; |
|
475 iRetryCounterSum = 0; |
|
476 iRetryTimerUse = EFalse; |
|
477 } |
|
478 if (!retry) |
|
479 { |
|
480 iRetryCounter = 0; |
|
481 iRetryCounterSum = 0; |
|
482 } |
|
483 return retry; |
|
484 } |
|
485 |
|
486 // ----------------------------------------------------------------------------- |
|
487 // CSIPIetfProfileContext::ShouldRetryRegistration |
|
488 // ----------------------------------------------------------------------------- |
|
489 // |
|
490 TBool CSIPIetfProfileContext::ShouldRetryRegistration( TInt aError ) |
|
491 { |
|
492 return (aError == K503ServiceUnavailable || |
|
493 aError == KErrSIPOutboundProxyNotResponding || |
|
494 aError == KErrTimedOut || |
|
495 ((aError == KErrSIPResolvingFailure || |
|
496 aError == KErrSIPTransportFailure || |
|
497 aError == KErrSIPICMPFailure) && |
|
498 iConnection.State() != CSIPConnection::ESuspended)); |
|
499 } |
|
500 |
|
501 // ----------------------------------------------------------------------------- |
|
502 // CSIPIetfProfileContext::InitializeRetryTimerValue |
|
503 // ----------------------------------------------------------------------------- |
|
504 // |
|
505 void CSIPIetfProfileContext::InitializeRetryTimerValue() |
|
506 { |
|
507 iRetryTimerUse = 0; |
|
508 } |
|
509 |
|
510 // ----------------------------------------------------------------------------- |
|
511 // CSIPIetfProfileContext::ConnectionStateChangedImpl |
|
512 // (other items were commented in a header). |
|
513 // ----------------------------------------------------------------------------- |
|
514 // |
|
515 void CSIPIetfProfileContext::ConnectionStateChangedImpl( |
|
516 CSIPConnection::TState /*aState*/) |
|
517 { |
|
518 } |
|
519 |
|
520 // ----------------------------------------------------------------------------- |
|
521 // CSIPIetfProfileContext::DeregisterL |
|
522 // (other items were commented in a header). |
|
523 // ----------------------------------------------------------------------------- |
|
524 // |
|
525 void CSIPIetfProfileContext::DeregisterL() |
|
526 { |
|
527 PROFILE_DEBUG4("CSIPIetfProfileContext::DeregisterL", ProfileId()\ |
|
528 , iCurrentState->Name()) |
|
529 iCurrentState->DeregisterL(*this); |
|
530 } |
|
531 |
|
532 // ----------------------------------------------------------------------------- |
|
533 // CSIPIetfProfileContext::UpdateL |
|
534 // (other items were commented in a header). |
|
535 // ----------------------------------------------------------------------------- |
|
536 // |
|
537 void CSIPIetfProfileContext::UpdateL( |
|
538 CSIPConcreteProfile& aNewProfile) |
|
539 { |
|
540 PROFILE_DEBUG4("CSIPIetfProfileContext::UpdateL", ProfileId()\ |
|
541 , iCurrentState->Name()) |
|
542 iCurrentState->UpdateL(*this, aNewProfile); |
|
543 } |
|
544 |
|
545 // ----------------------------------------------------------------------------- |
|
546 // CSIPIetfProfileContext::IncomingResponse() |
|
547 // (other items were commented in a header). |
|
548 // ----------------------------------------------------------------------------- |
|
549 // |
|
550 void CSIPIetfProfileContext::IncomingResponse( |
|
551 CSIPClientTransaction& aTransaction, |
|
552 CSIPRegistrationBinding& aRegistration, |
|
553 TBool& aHandled) |
|
554 { |
|
555 if (iClientTx && iRegistration && |
|
556 aTransaction==*iClientTx && aRegistration==*iRegistration) |
|
557 { |
|
558 PROFILE_DEBUG3("SIPIetfProfileContext::IncomingResponse", ProfileId()) |
|
559 aHandled = ETrue; |
|
560 const CSIPResponseElements* response = aTransaction.ResponseElements(); |
|
561 if (response) |
|
562 { |
|
563 TUint responseCode = response->StatusCode(); |
|
564 if (responseCode >= K300MultipleChoices) |
|
565 { |
|
566 PROFILE_DEBUG1("IETFProfileContext: registration failed") |
|
567 RetryPossible(responseCode); |
|
568 } |
|
569 else |
|
570 { |
|
571 if (responseCode >= K200Ok) |
|
572 { |
|
573 PROFILE_DEBUG1("IETFProfileContext: registration complete") |
|
574 iRetryCounter = 0; |
|
575 iRetryCounterSum = 0; |
|
576 Received2XXRegisterResponse(); |
|
577 } |
|
578 } |
|
579 } |
|
580 iCurrentState->ResponseReceived(*this, aTransaction); |
|
581 } |
|
582 } |
|
583 |
|
584 // ----------------------------------------------------------------------------- |
|
585 // CSIPIetfProfileContext::RandomPercent() |
|
586 // (other items were commented in a header). |
|
587 // ----------------------------------------------------------------------------- |
|
588 // |
|
589 TUint CSIPIetfProfileContext::RandomPercent() |
|
590 { |
|
591 const TInt rand = Math::Rand(iRandomSeed); |
|
592 TInt result = 0; |
|
593 result = KMaxRandomLimit + (rand%KMaxRandomLimit); |
|
594 return result; |
|
595 } |
|
596 |
|
597 // ----------------------------------------------------------------------------- |
|
598 // CSIPIetfProfileContext::DelayTime() |
|
599 // (other items were commented in a header). |
|
600 // ----------------------------------------------------------------------------- |
|
601 // |
|
602 TUint CSIPIetfProfileContext::DelayTime() |
|
603 { |
|
604 PROFILE_DEBUG1("CSIPIetfProfileContext::DelayTime") |
|
605 TReal res; |
|
606 iRetryCounter++; |
|
607 iRetryCounterSum++; |
|
608 Math::Pow(res,KWaitTimeCoefficient,iRetryCounter); |
|
609 TUint respond = res; |
|
610 TUint waitTime = KBaseTimeInSec*respond; |
|
611 if (waitTime > 1800) |
|
612 { |
|
613 waitTime = 1800; |
|
614 } |
|
615 return ((waitTime*RandomPercent())/KRandomDivider); |
|
616 } |
|
617 |
|
618 // ----------------------------------------------------------------------------- |
|
619 // CSIPIetfProfileContext::RetryTimerInUse() |
|
620 // (other items were commented in a header). |
|
621 // ----------------------------------------------------------------------------- |
|
622 // |
|
623 TBool CSIPIetfProfileContext::RetryTimerInUse() |
|
624 { |
|
625 return iRetryTimerUse; |
|
626 } |
|
627 |
|
628 // ----------------------------------------------------------------------------- |
|
629 // CSIPIetfProfileContext::IsAddressSIPSURIL() |
|
630 // (other items were commented in a header). |
|
631 // ----------------------------------------------------------------------------- |
|
632 // |
|
633 TBool CSIPIetfProfileContext::IsAddressSIPSURIL(const TDesC8& aValue) const |
|
634 { |
|
635 __ASSERT_ALWAYS (aValue.Length() > 0, User::Leave(KErrArgument)); |
|
636 TUriParser8 uriParser; |
|
637 User::LeaveIfError(uriParser.Parse(aValue)); |
|
638 TPtrC8 sips(SIPStrings::StringF(SipStrConsts::ESips).DesC()); |
|
639 return (uriParser.Extract(EUriScheme).CompareF(sips) == 0); |
|
640 } |
|
641 |
|
642 // ----------------------------------------------------------------------------- |
|
643 // CSIPIetfProfileContext::SetAddressToSIPSURIL() |
|
644 // ----------------------------------------------------------------------------- |
|
645 // |
|
646 HBufC8* CSIPIetfProfileContext::SetAddressToSIPSURIL(const TDesC8& aValue) |
|
647 { |
|
648 TUriParser8 uriParser; |
|
649 User::LeaveIfError(uriParser.Parse(aValue)); |
|
650 CUri8* uri = CUri8::NewLC(uriParser); |
|
651 uri->SetComponentL( |
|
652 SIPStrings::StringF(SipStrConsts::ESips).DesC(),EUriScheme); |
|
653 HBufC8* value = uri->Uri().UriDes().AllocL(); |
|
654 CleanupStack::PopAndDestroy(uri); |
|
655 return value; |
|
656 } |
|
657 |
|
658 // ----------------------------------------------------------------------------- |
|
659 // CSIPIetfProfileContext::SetTlsToSecurityClientL() |
|
660 // (other items were commented in a header). |
|
661 // ----------------------------------------------------------------------------- |
|
662 // |
|
663 TBool CSIPIetfProfileContext::SetTlsToSecurityClientL() |
|
664 { |
|
665 TBool tlsSet = EFalse; |
|
666 if(!IsAddressSIPSURIL(iProfile->AOR()) && |
|
667 iProfile->IsSecurityNegotiationEnabled()) |
|
668 { |
|
669 const TDesC8& proxyAddr = ProxyAddressL(); |
|
670 if (proxyAddr.Length() > 0) |
|
671 { |
|
672 if(IsConfiguredOutboundProxySIPURIL(proxyAddr)|| |
|
673 IsDynamicNumericIPAddress(proxyAddr)) |
|
674 { |
|
675 tlsSet = ETrue; |
|
676 } |
|
677 } |
|
678 } |
|
679 return tlsSet; |
|
680 } |
|
681 |
|
682 // ----------------------------------------------------------------------------- |
|
683 // CSIPIetfProfileContext::IsDynamicNumericIPAddress() |
|
684 // (other items were commented in a header). |
|
685 // ----------------------------------------------------------------------------- |
|
686 // |
|
687 TBool CSIPIetfProfileContext::IsDynamicNumericIPAddress( const TDesC8& aValue ) |
|
688 { |
|
689 return ( IsProxyResolvingEnabled() && |
|
690 !( UriUtils::HostType( aValue ) == UriUtils::ETextHost ) ); |
|
691 } |
|
692 |
|
693 // ----------------------------------------------------------------------------- |
|
694 // CSIPIetfProfileContext::IsConfiguredOutboundProxySIPURIL() |
|
695 // (other items were commented in a header). |
|
696 // ----------------------------------------------------------------------------- |
|
697 // |
|
698 TBool CSIPIetfProfileContext::IsConfiguredOutboundProxySIPURIL( const TDesC8& aValue ) |
|
699 { |
|
700 return ( !IsProxyResolvingEnabled() && !IsAddressSIPSURIL(aValue) ); |
|
701 } |
|
702 |
|
703 // ----------------------------------------------------------------------------- |
|
704 // CSIPIetfProfileContext::CreateMsgElementsForUpdateLC |
|
705 // add SIP headers to REGISTER request |
|
706 // ----------------------------------------------------------------------------- |
|
707 // |
|
708 CSIPMessageElements* CSIPIetfProfileContext::CreateMsgElementsForUpdateLC( |
|
709 CSIPConcreteProfile& aProfile) |
|
710 { |
|
711 CSIPMessageElements* elements = CSIPMessageElements::NewLC(); |
|
712 |
|
713 RPointerArray<CSIPHeaderBase> headers; |
|
714 CSIPHeaderBase::PushLC(&headers); |
|
715 |
|
716 TInt sipHeaderCount = aProfile.SIPHeaders().MdcaCount(); |
|
717 for (TInt i=0; i < sipHeaderCount; i++) |
|
718 { |
|
719 TPtrC8 headerDes(aProfile.SIPHeaders().MdcaPoint(i)); |
|
720 CSIPHeaderBase* header = SIPMessageBuilder::CreateHeaderLC(headerDes); |
|
721 headers.AppendL(header); |
|
722 CleanupStack::Pop(header); |
|
723 } |
|
724 |
|
725 elements->SetUserHeadersL(headers); // An empty array is also allowed |
|
726 CleanupStack::Pop(1); // headers |
|
727 |
|
728 return elements; |
|
729 } |
|
730 |
|
731 // ----------------------------------------------------------------------------- |
|
732 // CSIPIetfProfileContext::TransportProtocol |
|
733 // ----------------------------------------------------------------------------- |
|
734 // |
|
735 RStringF CSIPIetfProfileContext::TransportProtocol(const CUri8& aUri) const |
|
736 { |
|
737 if (aUri.Uri().Extract(EUriPath).FindF(KTransportUdpParam) >= 0) |
|
738 { |
|
739 return SIPStrings::StringF(SipStrConsts::EUdp); |
|
740 } |
|
741 if (aUri.Uri().Extract(EUriPath).FindF(KTransportTcpParam) >= 0) |
|
742 { |
|
743 return SIPStrings::StringF(SipStrConsts::ETcp); |
|
744 } |
|
745 if (aUri.Uri().Extract(EUriPath).FindF(KTransportTlsParam) >= 0) |
|
746 { |
|
747 return SIPStrings::StringF(SipStrConsts::ETLS); |
|
748 } |
|
749 return SIPStrings::StringF(SipStrConsts::EEmpty); |
|
750 } |