|
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 : csip423responsereceived.cpp |
|
15 // Part of : SIP Registration |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "csip423responsereceived.h" |
|
22 #include "siprequest.h" |
|
23 #include "sipresponse.h" |
|
24 #include "sipcseqheader.h" |
|
25 #include "SipAssert.h" |
|
26 #include "MRegistrationOwner.h" |
|
27 #include "sipcontactheader.h" |
|
28 #include "CSIPRegistrar.h" |
|
29 #include "CSIPResponseUtility.h" |
|
30 #include "siperr.h" |
|
31 |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CSIP423ResponseReceived::NewL |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CSIP423ResponseReceived* CSIP423ResponseReceived::NewL( |
|
38 MRegistrationContext& aRegistration) |
|
39 { |
|
40 CSIP423ResponseReceived* self = |
|
41 CSIP423ResponseReceived::NewLC(aRegistration); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CSIP423ResponseReceived::NewLC |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CSIP423ResponseReceived* CSIP423ResponseReceived::NewLC( |
|
51 MRegistrationContext& aRegistration) |
|
52 { |
|
53 CSIP423ResponseReceived* self = |
|
54 new (ELeave) CSIP423ResponseReceived(aRegistration); |
|
55 CleanupStack::PushL(self); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CSIP423ResponseReceived::SetNeighbourStates |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CSIP423ResponseReceived::SetNeighbourStates( |
|
64 CSIPRegistrationState* aRegistered, |
|
65 CSIPRegistrationState* aUnregistered) |
|
66 { |
|
67 __SIP_ASSERT_RETURN(aRegistered, KErrArgument); |
|
68 __SIP_ASSERT_RETURN(aUnregistered, KErrArgument); |
|
69 |
|
70 iRegistered = aRegistered; |
|
71 iUnregistered = aUnregistered; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CSIP423ResponseReceived::~CSIP423ResponseReceived |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CSIP423ResponseReceived::~CSIP423ResponseReceived() |
|
79 { |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CSIP423ResponseReceived::RegisterL |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void CSIP423ResponseReceived::RegisterL(TTransactionId& aTransactionId, |
|
87 CSIPRequest* aRequest, |
|
88 CSIPRouteHeader* aOutboundProxy) |
|
89 { |
|
90 __SIP_ASSERT_LEAVE(aRequest, KErrArgument); |
|
91 |
|
92 CSIPCSeqHeader* cseq = aRequest->CSeq(); |
|
93 if (iRegistration.Registrar()) |
|
94 { |
|
95 // if there is Registrar, the CallId and CSeq must be filled-in |
|
96 // from CSIPRegistering state. the CSeq need to be increased for |
|
97 // sending REGISTER request again in this state. so panic if there is |
|
98 // no CSeq header in debug mode,leave in release mode |
|
99 __SIP_ASSERT_LEAVE(cseq != 0, KErrGeneral); |
|
100 // increase the cseq for registrar |
|
101 iRegistration.Registrar()->IncreaseCSeqNumber(); |
|
102 cseq->SetSeq(iRegistration.Registrar()->CSeqNumber()); |
|
103 } |
|
104 else |
|
105 { |
|
106 // to check if the CSeq has been filled by lower layer, |
|
107 // if so, increase the CSeq by one before sending the request. |
|
108 if (cseq) |
|
109 { |
|
110 cseq->SetSeq(cseq->Seq()+1); |
|
111 } |
|
112 } |
|
113 |
|
114 iRegistration.RegisterL(aTransactionId, aRequest, aOutboundProxy); |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CSIP423ResponseReceived::ReceiveL |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CSIP423ResponseReceived::ReceiveL(TTransactionId aTransactionId, |
|
122 CSIPResponse* aResponse) |
|
123 { |
|
124 __SIP_ASSERT_LEAVE(aResponse, KErrArgument); |
|
125 // the expires parameter value must not be 0, other wise panic in debug |
|
126 // mode, leaves in release mode. |
|
127 __SIP_ASSERT_LEAVE(iRegistration.Contact().ExpiresParameter() > 0, |
|
128 KErrGeneral); |
|
129 |
|
130 if (aResponse->Type() == CSIPResponse::E2XX) |
|
131 { |
|
132 // ConnectionMgr may have changed the the host part of the Contact |
|
133 iRegistration.UpdateContactFromRequestL(); |
|
134 TInt err = |
|
135 CSIPResponseUtility::Check2XXResponse(iRegistration,*aResponse); |
|
136 if (err) |
|
137 { |
|
138 iRegistration.ReceivedErrorResponseL(); |
|
139 PassErrorL(err,aTransactionId); |
|
140 delete aResponse; |
|
141 iRegistration.SelfDetach(ETrue); |
|
142 iRegistration.ChangeState(iUnregistered); |
|
143 } |
|
144 else |
|
145 { |
|
146 iRegistration.Received2XXResponseL(*aResponse,aTransactionId); |
|
147 // pass response to owner, registration id should be passed |
|
148 // since 2xx ok response received. |
|
149 PassResponseToOwnerL(aResponse, aTransactionId, |
|
150 iRegistration.RegistrationId()); |
|
151 |
|
152 // if EFalse,detach from lowerlayer only for nonrefresh binding. |
|
153 // Use overloaded version of SelfDetatch function |
|
154 // to detatch retry transaction. |
|
155 iRegistration.SelfDetach(EFalse, ETrue); |
|
156 |
|
157 // if the binding is non refresh binding, the request is deleted. |
|
158 iRegistration.ClearRequest(); |
|
159 iRegistration.ChangeState(iRegistered); |
|
160 } |
|
161 } |
|
162 else if (aResponse->IsErrorResponse()) |
|
163 { |
|
164 // ReceivedErrorResponseL, remove binding |
|
165 iRegistration.ReceivedErrorResponseL(); |
|
166 // pass response to owner |
|
167 PassResponseL(aResponse, aTransactionId); |
|
168 iRegistration.SelfDetach(ETrue); |
|
169 iRegistration.ChangeState(iUnregistered); |
|
170 } |
|
171 else // response type == 1XX |
|
172 { |
|
173 // pass provisional response to owner |
|
174 PassResponseL(aResponse, aTransactionId); |
|
175 } |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CSIP423ResponseReceived::TransactionEnded |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 TInt CSIP423ResponseReceived::TransactionEnded(TTransactionId aTransactionId, |
|
183 TInt aReason) |
|
184 { |
|
185 if (aReason != KErrNone) |
|
186 { |
|
187 iRegistration.ChangeState(iUnregistered); |
|
188 } |
|
189 // pass error to owner. |
|
190 if (iUpdate) |
|
191 { |
|
192 return (PassErrorToOwner(aReason, aTransactionId, |
|
193 iRegistration.RegistrationId())); |
|
194 } |
|
195 else |
|
196 { |
|
197 return (PassErrorToOwner(aReason, aTransactionId)); |
|
198 } |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CSIP423ResponseReceived::Retrying |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 |
|
206 TBool CSIP423ResponseReceived::Retrying() const |
|
207 |
|
208 { |
|
209 return ETrue; |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CSIP423ResponseReceived::SetUpdate |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CSIP423ResponseReceived::SetUpdate(TBool aUpdate) |
|
217 { |
|
218 iUpdate = aUpdate; |
|
219 } |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CSIP423ResponseReceived::CSIP423ResponseReceived |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 CSIP423ResponseReceived::CSIP423ResponseReceived( |
|
226 MRegistrationContext& aRegistration) |
|
227 : CSIPRegistrationState (aRegistration), |
|
228 iUpdate (EFalse) |
|
229 { |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CSIP423ResponseReceived::PassResponseL |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CSIP423ResponseReceived::PassResponseL(CSIPResponse* aResponse, |
|
237 TTransactionId aTransactionId) |
|
238 { |
|
239 if (iUpdate) |
|
240 { |
|
241 PassResponseToOwnerL(aResponse, aTransactionId, |
|
242 iRegistration.RegistrationId()); |
|
243 } |
|
244 else |
|
245 { |
|
246 PassResponseToOwnerL(aResponse, aTransactionId); |
|
247 } |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CSIP423ResponseReceived::PassErrorL |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void CSIP423ResponseReceived::PassErrorL(TInt aError, |
|
255 TTransactionId aTransactionId) |
|
256 { |
|
257 if (iUpdate) |
|
258 { |
|
259 User::LeaveIfError(PassErrorToOwner(aError, aTransactionId, |
|
260 iRegistration.RegistrationId())); |
|
261 } |
|
262 else |
|
263 { |
|
264 User::LeaveIfError(PassErrorToOwner(aError, aTransactionId)); |
|
265 } |
|
266 } |