|
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 // CStateSessionInitiation implementation file. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 |
|
26 #include "StateSessionInitiation.h" |
|
27 |
|
28 CStateSessionInitiation * CStateSessionInitiation::NewL( CSipStateMachine * aStateMachine ) |
|
29 /** |
|
30 Instantiaion static function |
|
31 */ |
|
32 { |
|
33 return new(ELeave) CStateSessionInitiation (aStateMachine); |
|
34 } |
|
35 |
|
36 CStateSessionInitiation::CStateSessionInitiation ( CSipStateMachine * aStateMachine ) : |
|
37 CSipStateBase ( aStateMachine, TSipHLConsts::EStateSessionInitiation ) |
|
38 /** |
|
39 Constuctor |
|
40 */ |
|
41 { |
|
42 // Open Logs |
|
43 __FLOG_OPEN(_L8("SipStateMachine"), _L8("StateSessionInitiation")); |
|
44 __FLOG_1(_L("[StateSessionInitiation]:[%x]::CStateSessionInitiation() "), this); |
|
45 } |
|
46 |
|
47 CStateSessionInitiation::~CStateSessionInitiation () |
|
48 /** |
|
49 Destructor |
|
50 */ |
|
51 { |
|
52 // Close Logging |
|
53 __FLOG_0(_L("[StateSessionInitiation]: CStateSessionInitiation::~CStateSessionInitiation()")); |
|
54 __FLOG_CLOSE; |
|
55 } |
|
56 |
|
57 CSipStateBase * CStateSessionInitiation::ProcessClientL( TRequestStatus & aStatus ) |
|
58 /** |
|
59 Function which process the request and responses from the client |
|
60 */ |
|
61 { |
|
62 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL()"), this); |
|
63 switch(iClientRequest) |
|
64 { |
|
65 case TSipHLConsts::ERequestBye: |
|
66 case TSipHLConsts::ERequestCancel: |
|
67 { |
|
68 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<REQUEST BYE/ REQUEST CANCEL>>"), this); |
|
69 TRAPD(err,iSipSM->SendCancelL()); |
|
70 if(err != KErrNone) |
|
71 { |
|
72 iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus); |
|
73 iSipSM->SetGeneralError(err); |
|
74 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
75 } |
|
76 else |
|
77 { |
|
78 iSipSM->SetSuspendRequest(ETrue); |
|
79 iNext = this; |
|
80 iNext->ResetRequestResponse(); |
|
81 } |
|
82 } |
|
83 break; |
|
84 default: |
|
85 { |
|
86 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<REQUEST DEFAULT>>"), this); |
|
87 if(iReqIdentifier == 1) |
|
88 { |
|
89 iSipSM->SetSuspendRequest(ETrue); |
|
90 iNext = this; |
|
91 } |
|
92 |
|
93 } |
|
94 } |
|
95 // Handle Response from client |
|
96 switch(iClientResponse) |
|
97 { |
|
98 case TSipHLConsts::EResponseInvite: |
|
99 { |
|
100 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<RESPONSE INVITE>>"), this); |
|
101 TRAPD(err,iSipSM->GenerateInviteResponseL(iSipSM->GetCommandContext().iServerTx, TSipHLConsts::EResponse200OK)); |
|
102 if(err != KErrNone) |
|
103 { |
|
104 iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus); |
|
105 iSipSM->SetGeneralError(err); |
|
106 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
107 } |
|
108 else |
|
109 { |
|
110 // expecting an ACK |
|
111 iSipSM->SetSuspendRequest(ETrue); |
|
112 iNext = this; |
|
113 iNext->ResetRequestResponse(); |
|
114 } |
|
115 } |
|
116 break; |
|
117 case TSipHLConsts::EResponseInviteReject: |
|
118 { |
|
119 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<RESPONSE INVITE REJECT>>"), this); |
|
120 TRAPD(err,iSipSM->GenerateInviteResponseL(iSipSM->GetCommandContext().iServerTx, TSipHLConsts::EResponseReject)); |
|
121 if(err != KErrNone) |
|
122 { |
|
123 iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus); |
|
124 iSipSM->SetGeneralError(err); |
|
125 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
126 } |
|
127 else |
|
128 { |
|
129 iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus); |
|
130 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
131 iNext->ResetRequestResponse(); |
|
132 } |
|
133 } |
|
134 break; |
|
135 default: |
|
136 { |
|
137 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<RESPONSE DEFAULT>>"), this); |
|
138 if(iReqIdentifier == 3) |
|
139 { |
|
140 iSipSM->SetSuspendRequest(ETrue); |
|
141 iNext = this; |
|
142 } |
|
143 } |
|
144 } |
|
145 TRequestStatus * stat = &aStatus; |
|
146 User::RequestComplete(stat, KErrNone); |
|
147 #ifdef __FLOG_ACTIVE |
|
148 // This indormation is required only when logging is enabled |
|
149 TSipHLConsts::SIP_STATES iD = (iNext != NULL)?iNext->GetStateId() : TSipHLConsts::EStateNone; |
|
150 if(iD == TSipHLConsts::EStateNone) |
|
151 { |
|
152 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<Next State --> NULL>> "), this); |
|
153 } |
|
154 if(iD == TSipHLConsts::EStateSessionIdle) |
|
155 { |
|
156 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<Next State --> StateIdle>> "), this); |
|
157 } |
|
158 else if(iD == TSipHLConsts::EStateSessionInitiation) |
|
159 { |
|
160 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<Next State --> StateSessionInitiation>> "), this); |
|
161 } |
|
162 else if(iD == TSipHLConsts::EStateSessionEstablished) |
|
163 { |
|
164 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<Next State --> StateSessionEstablished>> "), this); |
|
165 } |
|
166 else if(iD == TSipHLConsts::EStateSessionTerminated) |
|
167 { |
|
168 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<Next State --> StateSessionTerminated>> "), this); |
|
169 } |
|
170 else |
|
171 { |
|
172 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessClientL() <<Next State --> Unknown, its a serious error>> "), this); |
|
173 } |
|
174 #endif |
|
175 return iNext; |
|
176 } |
|
177 |
|
178 CSipStateBase * CStateSessionInitiation::ProcessServerL( TRequestStatus & aStatus ) |
|
179 /** |
|
180 Function which process the request and responses from the Server |
|
181 */ |
|
182 { |
|
183 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL()"), this); |
|
184 TSipMsgBundle SipMsgBundle = iSipSM->GetSipMessageBundle(); |
|
185 // Handle Response from Server |
|
186 switch (iServerResponse) |
|
187 { |
|
188 case TSipHLConsts::EResponseInvite: |
|
189 { |
|
190 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<RESPONSE INVITE>>"), this); |
|
191 iSipSM->SetOutgoingStatus(EFalse); |
|
192 if(SipMsgBundle.iStatusCode == 200) |
|
193 { |
|
194 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<200 OK>>"), this); |
|
195 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionEstablished); |
|
196 iNext->ResetRequestResponse(); |
|
197 iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus); |
|
198 iNext->SetClientRequest(TSipHLConsts::ERequestAck); |
|
199 } |
|
200 else if(SipMsgBundle.iStatusCode == 487) |
|
201 { |
|
202 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<487 Request Terminated>>"), this); |
|
203 iSipSM->SetSIPError(SipMsgBundle.iStatusCode); |
|
204 iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus); |
|
205 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
206 iNext->ResetRequestResponse(); |
|
207 } |
|
208 else |
|
209 { |
|
210 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<Error neither 200 nor 487>>"), this); |
|
211 iSipSM->SetSIPError(SipMsgBundle.iStatusCode); |
|
212 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
213 } |
|
214 } |
|
215 break; |
|
216 case TSipHLConsts::EResponseCancel: |
|
217 { |
|
218 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<RESPONSE CANCEL>>"), this); |
|
219 if(SipMsgBundle.iStatusCode == 200) |
|
220 { |
|
221 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<200 OK>>"), this); |
|
222 iSipSM->SetSuspendRequest(ETrue); |
|
223 iNext = this; |
|
224 } |
|
225 else |
|
226 { |
|
227 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<Not 200 OK for cancel>>"), this); |
|
228 iSipSM->SetSIPError(SipMsgBundle.iStatusCode); |
|
229 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
230 } |
|
231 } |
|
232 break; |
|
233 default: |
|
234 { |
|
235 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<RESPONSE DEFAULT>>"), this); |
|
236 if(iReqIdentifier == 4) |
|
237 { |
|
238 iSipSM->SetSuspendRequest(ETrue); |
|
239 iNext = this; |
|
240 } |
|
241 } |
|
242 } |
|
243 // Handle request from server |
|
244 switch(iServerRequest) |
|
245 { |
|
246 case TSipHLConsts::ERequestCancel: |
|
247 { |
|
248 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<REQUEST CANCEL>>"), this); |
|
249 iSipSM->GetCommandContext().iAckCancel = ETrue; |
|
250 // This is not seems to be correct , but stack is not observing |
|
251 // standard behavior |
|
252 iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus); |
|
253 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
254 iNext->ResetRequestResponse(); |
|
255 } |
|
256 break; |
|
257 case TSipHLConsts::ERequestBye: |
|
258 { |
|
259 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<REQUEST BYE>>"), this); |
|
260 TRAPD(err,iSipSM->SendByeResponseL()); |
|
261 if(err != KErrNone) |
|
262 { |
|
263 iSipSM->SetGeneralError(err); |
|
264 } |
|
265 iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus); |
|
266 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
267 iNext->ResetRequestResponse(); |
|
268 } |
|
269 break; |
|
270 case TSipHLConsts::ERequestAck: |
|
271 { |
|
272 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<REQUEST ACK>>"), this); |
|
273 if(iSipSM->GetCommandContext().iAckCancel) |
|
274 { |
|
275 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
276 } |
|
277 else |
|
278 { |
|
279 iSipSM->CallEstablishedCallback(); |
|
280 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionEstablished); |
|
281 iNext->ResetRequestResponse(); |
|
282 iSipSM->SetSuspendRequest(ETrue); |
|
283 } |
|
284 } |
|
285 break; |
|
286 default: |
|
287 { |
|
288 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<REQUEST DEFAULT>>"), this); |
|
289 if(iReqIdentifier == 2) |
|
290 { |
|
291 iSipSM->SetSuspendRequest(ETrue); |
|
292 iNext = this; |
|
293 } |
|
294 } |
|
295 } |
|
296 TRequestStatus * stat = &aStatus; |
|
297 User::RequestComplete(stat , KErrNone); |
|
298 #ifdef __FLOG_ACTIVE |
|
299 // This indormation is required only when logging is enabled |
|
300 TSipHLConsts::SIP_STATES iD = (iNext != NULL)?iNext->GetStateId() : TSipHLConsts::EStateNone; |
|
301 if(iD == KErrNotFound) |
|
302 { |
|
303 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<Next State --> NULL>> "), this); |
|
304 } |
|
305 if(iD == TSipHLConsts::EStateSessionIdle) |
|
306 { |
|
307 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<Next State --> StateIdle>> "), this); |
|
308 } |
|
309 else if(iD == TSipHLConsts::EStateSessionInitiation) |
|
310 { |
|
311 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<Next State --> StateSessionInitiation>> "), this); |
|
312 } |
|
313 else if(iD == TSipHLConsts::EStateSessionEstablished) |
|
314 { |
|
315 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<Next State --> StateSessionEstablished>> "), this); |
|
316 } |
|
317 else if(iD == TSipHLConsts::EStateSessionTerminated) |
|
318 { |
|
319 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<Next State --> StateSessionTerminated>> "), this); |
|
320 } |
|
321 else |
|
322 { |
|
323 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerL() <<Next State --> Unknown, its a serious error>> "), this); |
|
324 } |
|
325 #endif |
|
326 return iNext; |
|
327 } |
|
328 |
|
329 CSipStateBase * CStateSessionInitiation::ProcessServerErrorL(TRequestStatus & aStatus) |
|
330 /** |
|
331 Handles the Error condition for this state from the serevr |
|
332 */ |
|
333 { |
|
334 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerErrorL()"), this); |
|
335 TSipMsgBundle SipMsgBundle = iSipSM->GetSipMessageBundle(); |
|
336 // Call the call back to Notify the client |
|
337 iSipSM->SetGeneralError(SipMsgBundle.iErrCode); |
|
338 iSipSM->SetSIPError(SipMsgBundle.iStatusCode); |
|
339 iSipSM->CallTerminateCallback(); |
|
340 iSipSM->SetCallTerminateCallBack(EFalse); |
|
341 // Get to The terminated state |
|
342 iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated); |
|
343 iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus); |
|
344 if(iNext) |
|
345 { |
|
346 iNext->ResetRequestResponse(); |
|
347 } |
|
348 TRequestStatus * stat = &aStatus; |
|
349 User::RequestComplete(stat, KErrNone); |
|
350 #ifdef __FLOG_ACTIVE |
|
351 // This indormation is required only when logging is enabled |
|
352 TSipHLConsts::SIP_STATES iD = (iNext != NULL)?iNext->GetStateId() : TSipHLConsts::EStateNone; |
|
353 if(iD == KErrNotFound) |
|
354 { |
|
355 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerErrorL() <<Next State --> NULL>> "), this); |
|
356 } |
|
357 if(iD == TSipHLConsts::EStateSessionIdle) |
|
358 { |
|
359 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerErrorL() <<Next State --> StateIdle>> "), this); |
|
360 } |
|
361 else if(iD == TSipHLConsts::EStateSessionInitiation) |
|
362 { |
|
363 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerErrorL() <<Next State --> StateSessionInitiation>> "), this); |
|
364 } |
|
365 else if(iD == TSipHLConsts::EStateSessionEstablished) |
|
366 { |
|
367 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerErrorL() <<Next State --> StateSessionEstablished>> "), this); |
|
368 } |
|
369 else if(iD == TSipHLConsts::EStateSessionTerminated) |
|
370 { |
|
371 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerErrorL() <<Next State --> StateSessionTerminated>> "), this); |
|
372 } |
|
373 else |
|
374 { |
|
375 __FLOG_1(_L("[StateSessionInitiation]:CStateSessionInitiation[%x]::ProcessServerErrorL() <<Next State --> Unknown, its a serious error>> "), this); |
|
376 } |
|
377 #endif |
|
378 return iNext; |
|
379 } |
|
380 |
|
381 |
|
382 |