|
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 : SipDialogAssocImplementation.cpp |
|
15 // Part of : SIPAPI |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "siperr.h" |
|
22 #include "sipstrings.h" |
|
23 #include "sipdialogassocbase.h" |
|
24 #include "SipDialogAssocImplementation.h" |
|
25 #include "sipclienttransaction.h" |
|
26 #include "sipservertransaction.h" |
|
27 #include "SipDialogImplementation.h" |
|
28 #include "SipConnectionImplementation.h" |
|
29 #include "csipdialogresponsesender.h" |
|
30 #include "sipmessageelements.h" |
|
31 #include "sipheaderbase.h" |
|
32 #include "MessageHeaderCleanup.h" |
|
33 #include "SipAssert.h" |
|
34 |
|
35 #ifdef CPPUNIT_TEST |
|
36 #include "TestCleanupStack.h" |
|
37 #endif |
|
38 |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CSIPDialogAssocImplementation::NewL |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CSIPDialogAssocImplementation* |
|
45 CSIPDialogAssocImplementation::NewL(RStringF aType, |
|
46 CSIPDialogAssocBase& aAssoc, |
|
47 CSIPDialog& aDialog) |
|
48 { |
|
49 CSIPDialogAssocImplementation* self = |
|
50 new (ELeave) CSIPDialogAssocImplementation(aAssoc, aDialog); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(aType); |
|
53 CleanupStack::Pop(self); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CSIPDialogAssocImplementation::NewL |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CSIPDialogAssocImplementation* |
|
62 CSIPDialogAssocImplementation::NewL(RStringF aType, |
|
63 CSIPDialogAssocBase& aAssoc, |
|
64 CSIPDialog& aDialog, |
|
65 CSIPServerTransaction& aTransaction) |
|
66 { |
|
67 CSIPDialogAssocImplementation* self = |
|
68 new (ELeave) CSIPDialogAssocImplementation(aAssoc, aDialog); |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(aType, aTransaction); |
|
71 CleanupStack::Pop(self); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CSIPDialogAssocImplementation::CSIPDialogAssocImplementation |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CSIPDialogAssocImplementation::CSIPDialogAssocImplementation( |
|
80 CSIPDialogAssocBase& aAssoc, |
|
81 CSIPDialog& aDialog) : |
|
82 iAssoc(aAssoc), |
|
83 iDialog(aDialog) |
|
84 #ifdef CPPUNIT_TEST |
|
85 , iTransactions(1) |
|
86 #endif |
|
87 , iStringPoolOpened(EFalse) |
|
88 { |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CSIPDialogAssocImplementation::ConstructL |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CSIPDialogAssocImplementation::ConstructL(RStringF aType) |
|
96 { |
|
97 SIPStrings::OpenL(); |
|
98 iStringPoolOpened = ETrue; |
|
99 iType = aType.Copy(); |
|
100 iDialog.Implementation().AddAssocL(iAssoc, iType); |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CSIPDialogAssocImplementation::ConstructL |
|
105 // A request (aTransaction) has been received from network and application has |
|
106 // created a dialog assoc for it. |
|
107 // aTransaction is currently associated with CSIPConnection, and should |
|
108 // now be associated with this dialog assoc. |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void |
|
112 CSIPDialogAssocImplementation::ConstructL(RStringF aType, |
|
113 CSIPServerTransaction& aTransaction) |
|
114 { |
|
115 CSIPTransactionBase::TState state = aTransaction.StateL(); |
|
116 if (state != CSIPTransactionBase::ETrying && |
|
117 state != CSIPTransactionBase::EProceeding) |
|
118 { |
|
119 User::Leave(KErrSIPInvalidTransactionState); |
|
120 } |
|
121 |
|
122 //Set dialog related sender instance for the aTransaction to use |
|
123 aTransaction.SetResponseSender( |
|
124 CSIPDialogResponseSender::NewL(iDialog.Implementation())); |
|
125 |
|
126 aTransaction.ReAssociateL(*this); |
|
127 |
|
128 //Attach CSIPDialogAssocImplementation to dialog after everything else |
|
129 ConstructL(aType); |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CSIPDialogAssocImplementation::~CSIPDialogAssocImplementation |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 CSIPDialogAssocImplementation::~CSIPDialogAssocImplementation() |
|
137 { |
|
138 iDialog.Implementation().RemoveAssoc(iAssoc); |
|
139 |
|
140 //Transactions are not deleted, since application owns them. |
|
141 for (TInt i = 0; i < iTransactions.Count(); i++) |
|
142 { |
|
143 iTransactions[i]->Detach(*this); |
|
144 } |
|
145 iTransactions.Reset(); |
|
146 |
|
147 iType.Close(); |
|
148 if (iStringPoolOpened) |
|
149 { |
|
150 SIPStrings::Close(); |
|
151 } |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CSIPDialogAssocImplementation::Dialog |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 const CSIPDialog& CSIPDialogAssocImplementation::Dialog() const |
|
159 { |
|
160 return iDialog; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CSIPDialogAssocImplementation::Dialog |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 CSIPDialog& CSIPDialogAssocImplementation::Dialog() |
|
168 { |
|
169 return iDialog; |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CSIPDialogAssocImplementation::SendNonTargetRefreshRequestL |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 CSIPClientTransaction* |
|
177 CSIPDialogAssocImplementation::SendNonTargetRefreshRequestL(RStringF aMethod, |
|
178 CSIPMessageElements* aElements) |
|
179 { |
|
180 return iDialog.Implementation().SendNonTargetRefreshRequestL(*this, |
|
181 aMethod, |
|
182 aElements); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CSIPDialogAssocImplementation::Type |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 RStringF CSIPDialogAssocImplementation::Type() const |
|
190 { |
|
191 return iType; |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CSIPDialogAssocImplementation::ClientConnectionL |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 CSIPClientConnection& CSIPDialogAssocImplementation::ClientConnectionL() |
|
199 { |
|
200 CSIPClientConnection* clientConn = ClientConnection(); |
|
201 if (!clientConn) |
|
202 { |
|
203 User::Leave(KErrSIPResourceNotAvailable); |
|
204 } |
|
205 return *clientConn; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CSIPDialogAssocImplementation::ClientConnection |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 CSIPClientConnection* CSIPDialogAssocImplementation::ClientConnection() |
|
213 { |
|
214 CSIPConnection* conn = iDialog.Connection(); |
|
215 |
|
216 if (conn) |
|
217 { |
|
218 return conn->Implementation().ClientConnection(); |
|
219 } |
|
220 return NULL; |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CSIPDialogAssocImplementation::SIPConnectionL |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 CSIPConnection& CSIPDialogAssocImplementation::SIPConnectionL() |
|
228 { |
|
229 CSIPConnection* conn = iDialog.Connection(); |
|
230 if (!conn) |
|
231 { |
|
232 User::Leave(KErrSIPResourceNotAvailable); |
|
233 } |
|
234 |
|
235 return *conn; |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CSIPDialogAssocImplementation::AddTransactionL |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 void CSIPDialogAssocImplementation::AddTransactionL( |
|
243 CSIPTransactionBase& aTransaction) |
|
244 { |
|
245 iTransactions.AppendL(&aTransaction); |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CSIPDialogAssocImplementation::RemoveTransaction |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 void CSIPDialogAssocImplementation::RemoveTransaction( |
|
253 const CSIPTransactionBase& aTransaction) |
|
254 { |
|
255 TInt pos = iTransactions.Find(&aTransaction); |
|
256 |
|
257 if (pos != KErrNotFound) |
|
258 { |
|
259 iTransactions.Remove(pos); |
|
260 } |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CSIPDialogAssocImplementation::UpdateRefreshL |
|
265 // Application is not allowed to update or terminate a dialog association |
|
266 // related refresh. |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 CSIPClientTransaction* CSIPDialogAssocImplementation::UpdateRefreshL( |
|
270 CSIPRefresh& /*aRefresh*/, |
|
271 CSIPMessageElements* /*aElements*/, |
|
272 TBool /*aTerminate*/) |
|
273 { |
|
274 User::Leave(KErrSIPInvalidDialogState); |
|
275 return NULL; |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CSIPDialogAssocImplementation::DeletingRefresh |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CSIPDialogAssocImplementation::DeletingRefresh(CSIPRefresh& aRefresh, |
|
283 TUint32 aRefreshId) |
|
284 { |
|
285 iAssoc.DeletingRefresh(aRefresh, aRefreshId); |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CSIPDialogAssocImplementation::TransactionAssociation |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 MTransactionAssociation& CSIPDialogAssocImplementation::TransactionAssociation() |
|
293 { |
|
294 return *this; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CSIPDialogAssocImplementation::CheckIfStandAlone |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 TInt CSIPDialogAssocImplementation::CheckIfStandAlone() |
|
302 { |
|
303 return KErrSIPInvalidDialogState; |
|
304 } |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // CSIPDialogAssocImplementation::FindTransaction |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 CSIPTransactionBase* |
|
311 CSIPDialogAssocImplementation::FindTransaction(TUint32 aRequestId) |
|
312 { |
|
313 for (TInt i = 0; i < iTransactions.Count(); i++) |
|
314 { |
|
315 if (iTransactions[i]->RequestId() == aRequestId) |
|
316 { |
|
317 return iTransactions[i]; |
|
318 } |
|
319 } |
|
320 |
|
321 return NULL; |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CSIPDialogAssocImplementation::HasTransaction |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 TBool |
|
329 CSIPDialogAssocImplementation::HasTransaction(RStringF aType, |
|
330 TBool aIsClientTransaction) |
|
331 { |
|
332 for (TInt i = 0; i < iTransactions.Count(); i++) |
|
333 { |
|
334 if (iTransactions[i]->Type() == aType && |
|
335 iTransactions[i]->IsSIPClientTransaction() == aIsClientTransaction) |
|
336 { |
|
337 return ETrue; |
|
338 } |
|
339 } |
|
340 |
|
341 return EFalse; |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CSIPDialogAssocImplementation::ConnectionLost |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 void CSIPDialogAssocImplementation::ConnectionLost() |
|
349 { |
|
350 TInt i = 0; |
|
351 for (i = 0; i < iTransactions.Count(); i++) |
|
352 { |
|
353 iTransactions[i]->ChangeState(CSIPTransactionBase::ETerminated); |
|
354 } |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CSIPDialogAssocImplementation::CopyHeaderL |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 void |
|
362 CSIPDialogAssocImplementation::CopyHeaderL(const CSIPHeaderBase& aHeader, |
|
363 CSIPMessageElements& aElements, |
|
364 TMessageHeaderCleanup& aHeaderCleanup) |
|
365 { |
|
366 CSIPHeaderBase* newHeader = aHeader.CloneL(); |
|
367 CleanupStack::PushL(newHeader); |
|
368 aElements.AddHeaderL(newHeader); |
|
369 CleanupStack::Pop(newHeader); |
|
370 aHeaderCleanup.AddHeader(*newHeader); |
|
371 } |