|
1 /* |
|
2 * Copyright (c) 2005 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "mcestateconfirming.h" |
|
23 #include "mcesipsession.h" |
|
24 #include "mceactionset.h" |
|
25 #include "mcefcactionset.h" |
|
26 #include "mceclientserver.h" |
|
27 #include "mcesipextensions.h" |
|
28 #include "mcenatmacros.h" |
|
29 #include <sipdialogassocbase.h> |
|
30 #include <sipdialog.h> |
|
31 |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CMceStateConfirming::CMceStateConfirming |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CMceStateConfirming::CMceStateConfirming() |
|
38 : CMceState( KMceStateConfirming ) |
|
39 { |
|
40 } |
|
41 |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CMceStateConfirming::~CMceStateConfirming |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CMceStateConfirming::~CMceStateConfirming() |
|
48 { |
|
49 } |
|
50 |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CMceStateConfirming::DoAcceptL |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 TBool CMceStateConfirming::DoAcceptL( TMceStateTransitionEvent& aEvent ) |
|
57 { |
|
58 User::LeaveIfError( |
|
59 aEvent.Code() == EMceResponse || |
|
60 aEvent.Code() == EMceProvisionalResponse || |
|
61 aEvent.Code() == EMceRedirectionResponse || |
|
62 aEvent.Code() == EMceErrorResponse || |
|
63 aEvent.Code() == EMceItcCancel || |
|
64 aEvent.Code() == EMceMediaUpdated || |
|
65 aEvent.Code() == EMceItcEnable || |
|
66 aEvent.Code() == EMceItcDisable || |
|
67 IsExtensionRequestEvent( aEvent ) |
|
68 |
|
69 ? KErrNone : KErrTotalLossOfPrecision ); |
|
70 |
|
71 return ETrue; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CMceStateConfirming::EntryL |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 void CMceStateConfirming::EntryL( TMceStateTransitionEvent& aEvent ) |
|
79 { |
|
80 |
|
81 if ( IsExtensionRequestEvent( aEvent )) |
|
82 { |
|
83 HandleExtensionRequestEventL( aEvent ); |
|
84 } |
|
85 else |
|
86 { |
|
87 CMceSipSession& session = aEvent.Session(); |
|
88 switch ( aEvent.Code() ) |
|
89 { |
|
90 case EMceResponse: |
|
91 { |
|
92 EntryResponseL( aEvent ); |
|
93 break; |
|
94 } |
|
95 case EMceProvisionalResponse: |
|
96 { |
|
97 EntryProvisionalResponseL( aEvent ); |
|
98 break; |
|
99 } |
|
100 case EMceRedirectionResponse: |
|
101 case EMceErrorResponse: |
|
102 { |
|
103 EntryErrorResponseL( aEvent ); |
|
104 break; |
|
105 } |
|
106 case EMceItcCancel: |
|
107 { |
|
108 EntryCancelL( aEvent ); |
|
109 break; |
|
110 } |
|
111 case EMceMediaUpdated: |
|
112 { |
|
113 EntryMediaUpdatedL( aEvent ); |
|
114 break; |
|
115 } |
|
116 case EMceItcEnable: |
|
117 case EMceItcDisable: |
|
118 { |
|
119 session.Actions().ControlMediaL( aEvent.ParamIDs(), |
|
120 (TMceItcFunctions)aEvent.Code() ); |
|
121 break; |
|
122 } |
|
123 default: |
|
124 { |
|
125 // NOP |
|
126 break; |
|
127 } |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CMceStateConfirming::ExitL |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CMceStateConfirming::ExitL( TMceStateTransitionEvent& aEvent ) |
|
137 { |
|
138 |
|
139 if ( IsExtensionRequestEvent( aEvent )) |
|
140 { |
|
141 //Do Nothing; |
|
142 } |
|
143 |
|
144 else |
|
145 { |
|
146 CMceSipSession& session = aEvent.Session(); |
|
147 switch ( aEvent.Code() ) |
|
148 { |
|
149 case EMceMediaUpdated: |
|
150 { |
|
151 ExitMediaUpdatedL( aEvent ); |
|
152 break; |
|
153 } |
|
154 case EMceItcCancel: |
|
155 { |
|
156 session.Actions().StateChanged( KMceStateCanceled ); |
|
157 session.Actions().ClientStateChanged( aEvent.ParamIDs(), |
|
158 CMceSession::ECancelling ); |
|
159 break; |
|
160 } |
|
161 case EMceErrorResponse: |
|
162 case EMceRedirectionResponse: |
|
163 { |
|
164 // session canceled |
|
165 session.Actions().StateChanged( KMceStateCanceled ); |
|
166 session.Actions().ClientStateChangedL( CMceSession::ECancelling, |
|
167 session.Response() ); |
|
168 |
|
169 break; |
|
170 } |
|
171 default: |
|
172 { |
|
173 break; |
|
174 } |
|
175 } |
|
176 } |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CMceStateConfirming::EntryResponseL |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CMceStateConfirming::EntryResponseL( TMceStateTransitionEvent& aEvent ) |
|
184 { |
|
185 CMceSipSession& session = aEvent.Session(); |
|
186 RStringF trx = session.Response().Type(); |
|
187 |
|
188 TMceReturnStatus status = KMceReady; |
|
189 CSIPClientTransaction& response = session.Response(); |
|
190 TBool hasContent = MceSip::HasContent( response ); |
|
191 |
|
192 if ( trx == SIPStrings::StringF( SipStrConsts::EInvite ) ) |
|
193 { |
|
194 // 2xx to INVITE already, send ACK |
|
195 session.Actions().SendACKL( response ); |
|
196 |
|
197 if ( hasContent ) |
|
198 { |
|
199 // since the answer is already received, |
|
200 // seize resending UPDATE/PRACK |
|
201 TBool interrupted = session.Actions().InterruptConfirming(); |
|
202 User::LeaveIfError( interrupted ? |
|
203 KErrNone : KErrTotalLossOfPrecision ); |
|
204 |
|
205 // there is SDP, treat it as answer |
|
206 User::LeaveIfError( session.Actions().CreateSDP( response ) ); |
|
207 session.Actions().DecodeL(); |
|
208 status = session.Actions().UpdateL(); |
|
209 if ( status == KMceReady ) |
|
210 { |
|
211 if ( MCE_NEED_TO_SEND( session, NULL ) ) |
|
212 { |
|
213 // send re-INVITE |
|
214 session.Actions().EncodeL(); |
|
215 session.Actions().SendInviteL(); |
|
216 } |
|
217 aEvent.Code() = EMceMediaUpdated; |
|
218 } |
|
219 else if ( MCE_IS_ERROR( status ) ) |
|
220 { |
|
221 User::Leave( status ); |
|
222 } |
|
223 else // KMceAsync |
|
224 { |
|
225 // NOP |
|
226 } |
|
227 } |
|
228 else |
|
229 { |
|
230 // TODO: IF ( answerNeeded ) |
|
231 // THEN wait until the PRACK/UPDATE generates a response. |
|
232 // ELSE consider session established |
|
233 } |
|
234 } |
|
235 else if ( trx == SIPStrings::StringF( SipStrConsts::EUpdate ) || |
|
236 trx == SIPStrings::StringF( SipStrConsts::EPrack ) ) |
|
237 { |
|
238 // 2xx to PRACK/UPDATE |
|
239 |
|
240 if ( hasContent ) |
|
241 { |
|
242 NAT_WAIT_NO_EXEC( session, (status = session.Actions().CreateSDP( response ))); |
|
243 if ( !MCE_IS_ERROR( status ) && MCE_NEED_TO_SEND( session, NULL ) ) |
|
244 { |
|
245 if ( session.ActiveBody().SecureSession() ) |
|
246 { |
|
247 session.ActiveBody().SecureSession()->iLSReadyToBind = ETrue; |
|
248 } |
|
249 status = session.Actions().DecodeL(); |
|
250 if ( status == KMceSipPreconditionFailure ) |
|
251 { |
|
252 User::Leave( status ); |
|
253 } |
|
254 else |
|
255 { |
|
256 status = session.Actions().UpdateL(); |
|
257 } |
|
258 } |
|
259 } |
|
260 |
|
261 if ( status == KMceReady ) |
|
262 { |
|
263 if ( ( MCE_NEED_TO_SEND( session, NULL ) || |
|
264 ( trx == SIPStrings::StringF( SipStrConsts::EPrack ) && |
|
265 session.Extensions().RemoteIMSRel5() ) )&& |
|
266 session.ActiveBody().Modifier( KMceSecPreconditions )!= |
|
267 KMcePreconditionsE2ESupported ) |
|
268 |
|
269 { |
|
270 |
|
271 if (!hasContent) |
|
272 { |
|
273 // Do nothing. |
|
274 } |
|
275 else |
|
276 { |
|
277 status = session.Actions().UpdateL(); |
|
278 __ASSERT_ALWAYS( status == KMceReady, User::Leave( KErrArgument ) ); |
|
279 if ( session.ActiveBody().SecureSession() ) |
|
280 { |
|
281 session.ActiveBody().SecureSession()->iLSReadyToBind = ETrue; |
|
282 } |
|
283 NAT_WAIT_NO_EXEC( session, session.Actions().EncodeL() ); |
|
284 session.Actions().SendUpdateRequestL(); |
|
285 } |
|
286 } |
|
287 aEvent.Code() = EMceMediaUpdated; |
|
288 } |
|
289 else if ( MCE_IS_ERROR( status ) ) |
|
290 { |
|
291 User::Leave( status ); |
|
292 } |
|
293 else // KMceAsync |
|
294 { |
|
295 // NOP |
|
296 } |
|
297 aEvent.ParamStatus() = status; |
|
298 } |
|
299 else |
|
300 { |
|
301 User::Leave( KErrTotalLossOfPrecision ); |
|
302 } |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CMceStateConfirming::EntryProvisionalResponseL |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 void CMceStateConfirming::EntryProvisionalResponseL( |
|
310 TMceStateTransitionEvent& /*aEvent*/ ) |
|
311 { |
|
312 // IF retransmission THEN ignore |
|
313 // ELSE IF sent reliably THEN send PRACK |
|
314 // |
|
315 // IF 180 ringing THEN give to application |
|
316 // TBD: What if 180 Ringing comes here? |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CMceStateConfirming::EntryErrorResponseL |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 void CMceStateConfirming::EntryErrorResponseL( |
|
324 TMceStateTransitionEvent& aEvent ) |
|
325 { |
|
326 CMceSipSession& session = aEvent.Session(); |
|
327 RStringF trx = session.Response().Type(); |
|
328 TUint code = MceSip::ResponseCode( session.Response() ); |
|
329 |
|
330 if ( trx == SIPStrings::StringF( SipStrConsts::EInvite ) ) |
|
331 { |
|
332 if ( session.SubState() == CMceSipSession::EOffering ) |
|
333 { |
|
334 session.Actions().StateChanged( KMceStateTerminated ); |
|
335 session.Actions().ClientStateChangedL( CMceSession::ETerminated, |
|
336 session.Response() ); |
|
337 |
|
338 } |
|
339 |
|
340 else if ( session.SubState() == CMceSipSession::EUpdating || |
|
341 session.SubState() == CMceSipSession::ERefreshing ) |
|
342 { |
|
343 if ( code == KMceSipCallOrTransactionDoesNotExist || |
|
344 code == KMceSipRequestTimeout ) |
|
345 { |
|
346 session.Actions().UpdateFailed(); |
|
347 session.Actions().SendBYEL(); |
|
348 session.Actions().StopMedia(); |
|
349 session.FCActions().ReleaseFC(); |
|
350 session.Actions().StateChanged( KMceStateTerminated ); |
|
351 session.Actions().ClientStateChangedL( CMceSession::ETerminated, |
|
352 session.Response() ); |
|
353 } |
|
354 else |
|
355 { |
|
356 session.Actions().UpdateFailed(); |
|
357 session.Actions().StateChanged( KMceStateEstablished ); |
|
358 session.Actions().ClientStateChangedL( CMceSession::EEstablished, |
|
359 *session.Body(), |
|
360 session.Response(), |
|
361 KErrCancel ); |
|
362 } |
|
363 } |
|
364 |
|
365 } |
|
366 |
|
367 else if ( trx == SIPStrings::StringF( SipStrConsts::EUpdate ) || |
|
368 trx == SIPStrings::StringF( SipStrConsts::EPrack ) ) |
|
369 { |
|
370 EntryCancelL( aEvent ); |
|
371 } |
|
372 else |
|
373 { |
|
374 User::Leave( KErrTotalLossOfPrecision ); |
|
375 } |
|
376 } |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // CMceStateConfirming::EntryCancelL |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 void CMceStateConfirming::EntryCancelL( TMceStateTransitionEvent& aEvent ) |
|
383 { |
|
384 CMceSipSession& session = aEvent.Session(); |
|
385 CMceSipSession::TSubState subState = session.SubState(); |
|
386 |
|
387 //(try) send CANCEL |
|
388 session.Actions().SendCancelL(); |
|
389 |
|
390 if ( subState == CMceSipSession::EOffering ) |
|
391 { |
|
392 session.Actions().StopMedia(); |
|
393 session.FCActions().ReleaseFC(); |
|
394 } |
|
395 else if ( subState == CMceSipSession::EUpdating ) |
|
396 { |
|
397 session.Actions().UpdateFailed(); |
|
398 } |
|
399 } |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // CMceStateConfirming::EntryMediaUpdatedL |
|
403 // ----------------------------------------------------------------------------- |
|
404 // |
|
405 void CMceStateConfirming::EntryMediaUpdatedL( TMceStateTransitionEvent& aEvent ) |
|
406 { |
|
407 CMceSipSession& session = aEvent.Session(); |
|
408 |
|
409 if ( MCE_NEED_TO_SEND( session, NULL ) ) |
|
410 { |
|
411 NAT_WAIT_NO_EXEC( session, session.Actions().EncodeL() ); |
|
412 |
|
413 if ( session.Dialog()->Dialog().State() == CSIPDialog::EEarly ) |
|
414 { |
|
415 session.Actions().SendUpdateRequestL(); |
|
416 } |
|
417 else |
|
418 { |
|
419 session.Actions().SendInviteL(); |
|
420 } |
|
421 } |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CMceStateConfirming::ExitMediaUpdatedL |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 void CMceStateConfirming::ExitMediaUpdatedL( TMceStateTransitionEvent& aEvent ) |
|
429 { |
|
430 CMceSipSession& session = aEvent.Session(); |
|
431 CSIPClientTransaction* update = session.PendingTransaction( |
|
432 SIPStrings::StringF( SipStrConsts::EUpdate ) ); |
|
433 if ( update && !MceSip::TrxCompleted( *update ) ) |
|
434 { |
|
435 // just sent UPDATE |
|
436 session.Actions().StateChanged( KMceStateConfirming ); |
|
437 } |
|
438 else |
|
439 { |
|
440 CSIPClientTransaction* invite = session.PendingTransaction( |
|
441 SIPStrings::StringF( SipStrConsts::EInvite ) ); |
|
442 User::LeaveIfError( invite ? KErrNone : |
|
443 KErrTotalLossOfPrecision ); |
|
444 |
|
445 if ( invite->StateL() == CSIPTransactionBase::ETerminated ) |
|
446 { |
|
447 // Just go to established state |
|
448 session.Actions().ClientStateChangedL( |
|
449 CMceSession::EEstablished, |
|
450 *session.Body(), |
|
451 session.Response() ); |
|
452 session.Actions().StateChanged( KMceStateEstablished ); |
|
453 } |
|
454 else |
|
455 { |
|
456 session.Actions().StateChanged( KMceStateOffering ); |
|
457 } |
|
458 } |
|
459 } |
|
460 |
|
461 // End of file |