|
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 : sipdialogearly.cpp |
|
15 // Part of : SIPAPI |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "sip.h" |
|
22 #include "siperr.h" |
|
23 #include "SipAssert.h" |
|
24 #include "sipdialogearly.h" |
|
25 #include "SipDialogImplementation.h" |
|
26 #include "SipDialogAssocImplementation.h" |
|
27 #include "sipinvitedialogassoc.h" |
|
28 #include "sipsubscribedialogassoc.h" |
|
29 #include "sipservertransaction.h" |
|
30 #include "sipmessageelements.h" |
|
31 #include "sipresponseelements.h" |
|
32 #include "sipstrings.h" |
|
33 #include "sipstrconsts.h" |
|
34 |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CDialogEarly::NewL |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CDialogEarly* CDialogEarly::NewL() |
|
41 { |
|
42 return new (ELeave) CDialogEarly(); |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CDialogEarly::CDialogEarly |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CDialogEarly::CDialogEarly() |
|
50 { |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CDialogEarly::~CDialogEarly |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CDialogEarly::~CDialogEarly() |
|
58 { |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CDialogEarly::State |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CSIPDialog::TState CDialogEarly::State() const |
|
66 { |
|
67 return CSIPDialog::EEarly; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CDialogEarly::SetNeighbourStates |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CDialogEarly::SetNeighbourStates(CDialogState& aConfirmed, |
|
75 CDialogState& aTerminated) |
|
76 { |
|
77 iConfirmed = &aConfirmed; |
|
78 iTerminated = &aTerminated; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CDialogEarly::SendSubscribeL |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CSIPClientTransaction* |
|
86 CDialogEarly::SendSubscribeL(const CSIPDialogImplementation& /*aDialog*/, |
|
87 CSIPSubscribeDialogAssoc& aAssoc, |
|
88 CSIPMessageElements* aElements, |
|
89 CSIPRefresh* aRefresh) const |
|
90 { |
|
91 return aAssoc.DoSendSubscribeL(aElements, aRefresh, ETrue); |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CDialogEarly::SendNonTargetRefreshRequestL |
|
96 // Dialog has to be at least in "early" state, before a non target refresh |
|
97 // request can be sent. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 CSIPClientTransaction* CDialogEarly::SendNonTargetRefreshRequestL( |
|
101 const CSIPDialogImplementation& aDialog, |
|
102 CSIPDialogAssocImplementation& aAssoc, |
|
103 RStringF aMethod, |
|
104 CSIPMessageElements* aElements) const |
|
105 { |
|
106 return aDialog.SendRequestInDialogL(aAssoc, aMethod, aElements); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CDialogEarly::IncomingResponseL |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 TBool CDialogEarly::IncomingResponseL(CSIPDialogImplementation& aDialog, |
|
114 CSIPResponseElements* aElements, |
|
115 TUint32 aRequestId, |
|
116 TUint32 aDialogId, |
|
117 CConnectionCallback& aCallback) const |
|
118 { |
|
119 return IncomingResponseWithinDialogL(aDialog, |
|
120 aElements, |
|
121 aRequestId, |
|
122 aDialogId, |
|
123 aCallback, |
|
124 *this, |
|
125 *iConfirmed, |
|
126 *iTerminated); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CDialogEarly::IncomingResponseL |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 TBool CDialogEarly::IncomingResponseL(CSIPDialogImplementation& aDialog, |
|
134 CSIPResponseElements* aElements, |
|
135 TUint32 aRequestId, |
|
136 TUint32 aRefreshId, |
|
137 TUint32 /*aDialogId*/, |
|
138 CConnectionCallback& aCallback) const |
|
139 { |
|
140 return ResponseToRefreshL(aDialog, |
|
141 aElements, |
|
142 aRequestId, |
|
143 aRefreshId, |
|
144 aCallback, |
|
145 *this, |
|
146 *iConfirmed, |
|
147 *iTerminated); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CDialogEarly::IncomingRequestL |
|
152 // Enter next state before passing request to application, because application |
|
153 // may delete the last dialog association, causing CSIPDialog to be deleted and |
|
154 // CSIPDialog shouldn't be accessed after the callback. |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 TBool CDialogEarly::IncomingRequestL(CSIPDialogImplementation& aDialog, |
|
158 CSIPServerTransaction* aTransaction, |
|
159 CConnectionCallback& aCallback) const |
|
160 { |
|
161 __SIP_ASSERT_LEAVE(aTransaction, KErrArgument); |
|
162 |
|
163 if (aTransaction->Type() == SIPStrings::StringF(SipStrConsts::ENotify) && |
|
164 aDialog.DoesNotifyConfirmDialog()) |
|
165 { |
|
166 aDialog.ChangeState(iConfirmed); |
|
167 } |
|
168 |
|
169 return RequestReceivedL(aDialog, aTransaction, aCallback); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CDialogEarly::SendResponseL |
|
174 // Since at least one response has already been sent (it caused the dialog to |
|
175 // enter Early state), this response doesn't create dialog anymore. |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CDialogEarly::SendResponseL(CSIPDialogImplementation& aDialog, |
|
179 const CSIPResponseElements& aElements, |
|
180 TUint32 aRequestId, |
|
181 TBool aAffectsDialogState, |
|
182 TBool aTargetRefresh) const |
|
183 { |
|
184 SendResponseWithinDialogL(aDialog, aElements, aRequestId, aTargetRefresh); |
|
185 |
|
186 if (aAffectsDialogState) |
|
187 { |
|
188 if (aElements.StatusCode() >= 300) |
|
189 { |
|
190 aDialog.ChangeState(iTerminated); |
|
191 } |
|
192 else |
|
193 { |
|
194 if (aElements.StatusCode() >= 200) |
|
195 { |
|
196 aDialog.ChangeState(iConfirmed); |
|
197 } |
|
198 } |
|
199 } |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CDialogEarly::SendUpdateL |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 CSIPClientTransaction* |
|
207 CDialogEarly::SendPrackL(CSIPInviteDialogAssoc& aAssoc, |
|
208 CSIPMessageElements* aElements) const |
|
209 { |
|
210 return aAssoc.DoSendRequestWithinDialogL( |
|
211 SIPStrings::StringF(SipStrConsts::EPrack), |
|
212 aElements); |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CDialogEarly::SendUpdateL |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 CSIPClientTransaction* |
|
220 CDialogEarly::SendUpdateL(CSIPInviteDialogAssoc& aAssoc, |
|
221 CSIPMessageElements* aElements) const |
|
222 { |
|
223 return aAssoc.DoSendRequestWithinDialogL( |
|
224 SIPStrings::StringF(SipStrConsts::EUpdate), |
|
225 aElements); |
|
226 } |
|
227 |
|
228 // ----------------------------------------------------------------------------- |
|
229 // CDialogEarly::SendByeL |
|
230 // Caller can send BYE in Early state, but callee can't. |
|
231 // If aAssoc has an INVITE client transaction, it means our endpoint has sent |
|
232 // an INVITE since dialog state is Early. |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 CSIPClientTransaction* |
|
236 CDialogEarly::SendByeL(CSIPInviteDialogAssoc& aAssoc, |
|
237 CSIPMessageElements* aElements) const |
|
238 { |
|
239 if (!aAssoc.Implementation().HasTransaction(aAssoc.Type(), ETrue)) |
|
240 { |
|
241 User::Leave(KErrSIPInvalidDialogState); |
|
242 } |
|
243 |
|
244 return aAssoc.DoSendRequestWithinDialogL( |
|
245 SIPStrings::StringF(SipStrConsts::EBye), |
|
246 aElements); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CDialogEarly::ErrorOccured |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 TBool CDialogEarly::ErrorOccured(CSIPDialogImplementation& aDialog, |
|
254 TInt aError, |
|
255 TUint32 aRequestId, |
|
256 CConnectionCallback& aCallback) const |
|
257 { |
|
258 return HandleErrorOccurred(aDialog, |
|
259 aError, |
|
260 aRequestId, |
|
261 aCallback, |
|
262 *iTerminated); |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CDialogEarly::ErrorOccured |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 TBool CDialogEarly::ErrorOccured(CSIPDialogImplementation& aDialog, |
|
270 TInt aError, |
|
271 TUint32 aRefreshId, |
|
272 TUint32 /*aRequestId*/, |
|
273 CConnectionCallback& aCallback) const |
|
274 { |
|
275 return HandleRefreshErrorOccurred(aDialog, |
|
276 aError, |
|
277 aRefreshId, |
|
278 aCallback, |
|
279 *iTerminated); |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CDialogEarly::ConnectionLost |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 void CDialogEarly::ConnectionLost(CSIPDialogImplementation& aDialog) const |
|
287 { |
|
288 aDialog.ChangeState(iTerminated); |
|
289 } |