|
1 // Copyright (c) 2006-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 : registered.cpp |
|
15 // Part of : SIPAPI |
|
16 // Version : SIP/5.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "sip.h" |
|
22 #include "siperr.h" |
|
23 #include "SipAssert.h" |
|
24 #include "registered.h" |
|
25 #include "RegBindingImplementation.h" |
|
26 #include "sipresponseelements.h" |
|
27 #include "sipclienttransaction.h" |
|
28 #include "sipconnectioncallback.h" |
|
29 |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CRegistered::NewL |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CRegistered* CRegistered::NewL() |
|
36 { |
|
37 return new (ELeave) CRegistered(); |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CRegistered::CRegistered |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CRegistered::CRegistered() |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CRegistered::~CRegistered |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CRegistered::~CRegistered() |
|
53 { |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CRegistered::IsContextActive |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 TBool CRegistered::IsContextActive() const |
|
61 { |
|
62 return ETrue; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CRegistered::SetNeighbourStates |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CRegistered::SetNeighbourStates(CRegistrationState& aUnregistering, |
|
70 CRegistrationState& aUnregistered) |
|
71 { |
|
72 iUnregistering = &aUnregistering; |
|
73 iUnregistered = &aUnregistered; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CRegistered::DeregisterL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CSIPClientTransaction* |
|
81 CRegistered::DeregisterL(CRegBindingImplementation& aRegistration, |
|
82 CSIPMessageElements* aElements) const |
|
83 { |
|
84 CSIPClientTransaction* ta = aRegistration.DoDeregisterL(aElements); |
|
85 aRegistration.ChangeState(iUnregistering); |
|
86 |
|
87 return ta; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CRegistered::UpdateL |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 CSIPClientTransaction* |
|
95 CRegistered::UpdateL(CRegBindingImplementation& aRegistration, |
|
96 CSIPMessageElements* aElements, |
|
97 TUint* aExpirationValue) const |
|
98 { |
|
99 return aRegistration.DoUpdateL(aElements, aExpirationValue); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CRegistered::IncomingResponseL |
|
104 // When an existing refreshed registration ends with an error response, |
|
105 // aRequestId is the id of the transaction that received the error, not of the |
|
106 // transaction that originally created the refresh. |
|
107 // |
|
108 // CSIPRefresh can not be deleted even if the refresh ends (300-699 response). |
|
109 // User might use the same CSIPRegistrationBinding to register again, and the |
|
110 // CSIPRefresh would be used again. |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 TBool |
|
114 CRegistered::IncomingResponseL(CRegBindingImplementation& aRegistration, |
|
115 CSIPResponseElements* aElements, |
|
116 TUint32 aRequestId, |
|
117 TUint32 /*aRegistrationId*/, |
|
118 TUint32 aRefreshId, |
|
119 CConnectionCallback& aCallback) const |
|
120 { |
|
121 __SIP_ASSERT_LEAVE(aElements, KErrArgument); |
|
122 |
|
123 TUint statusCode = aElements->StatusCode(); |
|
124 |
|
125 if (statusCode >= 300) |
|
126 { |
|
127 aRegistration.RemoveRegisteredContact(); |
|
128 aRegistration.ChangeState(iUnregistered); |
|
129 } |
|
130 |
|
131 if (statusCode >= 200 && statusCode < 300) |
|
132 { |
|
133 aRegistration.UpdateRegisteredContactL(); |
|
134 } |
|
135 |
|
136 CSIPClientTransaction* ta = aRegistration.FindTransaction(aRequestId); |
|
137 if (ta) |
|
138 { |
|
139 ta->SetResponseElements(aElements); |
|
140 aCallback.Set(CConnectionCallback::EIncomingResponseInRegistration, |
|
141 ta, |
|
142 &aRegistration.Binding()); |
|
143 return ETrue; |
|
144 } |
|
145 |
|
146 //If a 2xx is received in registered state, it is a response to an updated |
|
147 //REGISTER. Now transaction was not found, meaning application has deleted |
|
148 //it, indicating it is not interested on the response or if the response is |
|
149 //3xx-6xx it may indicate a refresh has ended. |
|
150 if (aRefreshId != 0 && statusCode >= 300) |
|
151 { |
|
152 ta = aRegistration.CreateClientTransactionL(); |
|
153 ta->SetRequestId(aRequestId); |
|
154 ta->SetResponseElements(aElements); |
|
155 aRegistration.UpdateRefreshState(aElements->StatusCode()); |
|
156 |
|
157 aCallback.Set(CConnectionCallback::EErrorOccuredInRegistration, |
|
158 NULL, |
|
159 &aRegistration.Binding(), |
|
160 NULL, |
|
161 NULL, |
|
162 KErrSIPTerminatedWithResponse, |
|
163 ta); |
|
164 return ETrue; |
|
165 } |
|
166 delete aElements; |
|
167 return EFalse; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CRegistered::ErrorOccured |
|
172 // CSIPRefresh can not be deleted even if the refresh ends. Application might |
|
173 // use the same CSIPRegistrationBinding to register again, and the CSIPRefresh |
|
174 // would be used again. |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TBool CRegistered::ErrorOccured(CRegBindingImplementation& aRegistration, |
|
178 TInt aError, |
|
179 TUint32 aRequestId, |
|
180 CConnectionCallback& aCallback) const |
|
181 { |
|
182 return aRegistration.HandleError(aCallback, |
|
183 aError, |
|
184 aRequestId, |
|
185 *iUnregistered); |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CRegistered::RefreshState |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 CSIPRefresh::TState CRegistered::RefreshState() const |
|
193 { |
|
194 return CSIPRefresh::EActive; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CRegistered::ConnectionLost |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CRegistered::ConnectionLost(CRegBindingImplementation& aRegistration) const |
|
202 { |
|
203 aRegistration.ChangeState(iUnregistered); |
|
204 } |