|
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 : DialogsStore.cpp |
|
15 // Part of : SIPDialogs |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "DialogsStore.h" |
|
23 #include "TransactionItemStore.h" |
|
24 #include "DeleteMgr.h" |
|
25 #include "sipmessage.h" |
|
26 #include "SipStackServerDefs.h" |
|
27 #include "sipfromheader.h" |
|
28 #include "siptoheader.h" |
|
29 #include "sipcallidheader.h" |
|
30 #include "sipcseqheader.h" |
|
31 #include "sipaddress.h" |
|
32 #include "sipuri.h" |
|
33 #include "sipresponse.h" |
|
34 #include "siprequest.h" |
|
35 #include "sipstrings.h" |
|
36 #include "sipstrconsts.h" |
|
37 #include "TSIPTransportParams.h" |
|
38 |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CDialogsStore::NewL |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CDialogsStore* CDialogsStore::NewL() |
|
45 { |
|
46 CDialogsStore* self = new (ELeave) CDialogsStore; |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CDialogsStore::CDialogsStore |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CDialogsStore::CDialogsStore() |
|
55 : iList(CSipDialogItem::Offset()) |
|
56 { |
|
57 iTagParamName = SIPStrings::StringF(SipStrConsts::ETag); |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CDialogsStore::~CDialogsStore |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CDialogsStore::~CDialogsStore() |
|
65 { |
|
66 CSipDialogItem* listItem = iList.First(); |
|
67 |
|
68 while (iList.IsFirst(listItem) && !iList.IsEmpty()) |
|
69 { |
|
70 iList.Remove(*listItem); |
|
71 delete listItem; |
|
72 listItem = iList.First(); |
|
73 } |
|
74 |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CDialogsStore::AddDialogItem |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CDialogsStore::AddDialogItem(CSipDialogItem* aDialogItem) |
|
82 { |
|
83 iList.AddLast(*aDialogItem); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CDialogsStore::DialogItemsCount |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 TInt CDialogsStore::DialogItemsCount() |
|
91 { |
|
92 TSglQueIter<CSipDialogItem> listIter(iList); |
|
93 TInt counter = 0; |
|
94 for (CSipDialogItem* listItem = listIter++; listItem; listItem = listIter++) |
|
95 { |
|
96 counter++; |
|
97 } |
|
98 return counter; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CDialogsStore::Remove |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 TInt CDialogsStore::Remove (CSipDialogItem* aDialogItem) |
|
106 { |
|
107 TInt err = aDialogItem->DeleteMgr().AddDeleteRequest(aDialogItem); |
|
108 if (!err) |
|
109 { |
|
110 iList.Remove(*aDialogItem); |
|
111 } |
|
112 return err; |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CDialogsStore::RemoveAllWith |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 TInt CDialogsStore::RemoveAllWith (const MDialogOwner* aDialogOwner) |
|
120 { |
|
121 TInt err = KErrNotFound; |
|
122 TSglQueIter<CSipDialogItem> listIter(iList); |
|
123 for (CSipDialogItem* listItem = listIter++; listItem; listItem = listIter++) |
|
124 { |
|
125 if (listItem->DialogOwner() == aDialogOwner) |
|
126 { |
|
127 iList.Remove(*listItem); |
|
128 delete listItem; |
|
129 err = KErrNone; |
|
130 } |
|
131 } |
|
132 return err; |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CDialogsStore::RemoveAllEarlyDialogsWith |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 TInt CDialogsStore::RemoveAllEarlyDialogsWith (TTransactionId aTransactionId) |
|
140 { |
|
141 TInt err = KErrNotFound; |
|
142 TSglQueIter<CSipDialogItem> listIter(iList); |
|
143 for (CSipDialogItem* item = listIter++; item; item = listIter++) |
|
144 { |
|
145 if (item->HasTransactionItem(aTransactionId) && item->IsEarly()) |
|
146 { |
|
147 err = Remove(item); |
|
148 } |
|
149 } |
|
150 return err; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CDialogsStore::DeleteItemsWithThisIapId |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CDialogsStore::DeleteItemsWithThisIapId(TUint32 aIapId) |
|
158 { |
|
159 TSglQueIter<CSipDialogItem> listIter(iList); |
|
160 for (CSipDialogItem* listItem = listIter++; listItem; listItem = listIter++) |
|
161 { |
|
162 if (listItem->IapId() == aIapId) |
|
163 { |
|
164 iList.Remove(*listItem); |
|
165 delete listItem; |
|
166 } |
|
167 } |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CDialogsStore::FindDialogItem |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 CSipDialogItem* CDialogsStore::FindDialogItem(const TDialogId& aDialogId) |
|
175 { |
|
176 TSglQueIter<CSipDialogItem> iter(iList); |
|
177 for (CSipDialogItem* item = iter++; item; item = iter++) |
|
178 { |
|
179 if (item->DialogId() == aDialogId) |
|
180 { |
|
181 return item; |
|
182 } |
|
183 } |
|
184 return NULL; |
|
185 } |
|
186 |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CDialogsStore::FindDialogItem |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 CSipDialogItem* CDialogsStore::FindDialogItem(const TDialogId& aDialogId, |
|
193 const MDialogOwner* aDialogOwner) |
|
194 { |
|
195 TSglQueIter<CSipDialogItem> iter(iList); |
|
196 for (CSipDialogItem* item = iter++; item; item = iter++) |
|
197 { |
|
198 if (item->DialogId() == aDialogId && |
|
199 item->DialogOwner() == aDialogOwner) |
|
200 { |
|
201 return item; |
|
202 } |
|
203 } |
|
204 return NULL; |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CDialogsStore::FindDialogItemByTransaction |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 CSipDialogItem* CDialogsStore::FindDialogItemByTransaction( |
|
212 const TTransactionId& aTransactionId) |
|
213 { |
|
214 TSglQueIter<CSipDialogItem> iter(iList); |
|
215 for (CSipDialogItem* item = iter++; item; item = iter++) |
|
216 { |
|
217 if (item->HasTransactionItem(aTransactionId)) |
|
218 { |
|
219 return item; |
|
220 } |
|
221 } |
|
222 return NULL; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CDialogsStore::FindDialogItemForPass |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 CSipDialogItem* |
|
230 CDialogsStore::FindDialogItemForPass (TTransactionId aTransactionId, |
|
231 CSIPResponse* aResponse) |
|
232 { |
|
233 CSIPToHeader* to = aResponse->To(); |
|
234 if (to) |
|
235 { |
|
236 TSglQueIter<CSipDialogItem> listIter(iList); |
|
237 for (CSipDialogItem* item = listIter++; item; item = listIter++) |
|
238 { |
|
239 if (item->RemoteTagSet() && |
|
240 item->RemoteTag() == to->ParamValue(iTagParamName) && |
|
241 item->HasTransactionItem(aTransactionId)) |
|
242 { |
|
243 return item; |
|
244 } |
|
245 } |
|
246 } |
|
247 return 0; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CDialogsStore::DialogItemForRequest |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 CSipDialogItem* CDialogsStore::DialogItemForRequest(CSIPRequest* aRequest) |
|
255 { |
|
256 if (!aRequest) |
|
257 { |
|
258 return NULL; |
|
259 } |
|
260 |
|
261 TSglQueIter<CSipDialogItem> listIter(iList); |
|
262 for (CSipDialogItem* item = listIter++; item; item = listIter++) |
|
263 { |
|
264 if (item->Match(*aRequest)) |
|
265 { |
|
266 return item; |
|
267 } |
|
268 } |
|
269 return NULL; |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CDialogsStore::FindDialogItemByCallId |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 CSipDialogItem* CDialogsStore::FindDialogItemByCallId(CSIPMessage* aMessage) |
|
277 { |
|
278 if (aMessage) |
|
279 { |
|
280 TSglQueIter<CSipDialogItem> listIter(iList); |
|
281 CSIPCallIDHeader* callId = aMessage->CallID(); |
|
282 |
|
283 for (CSipDialogItem* item = listIter++; item; item = listIter++) |
|
284 { |
|
285 if (*callId == *item->CallId()) |
|
286 { |
|
287 return item; |
|
288 } |
|
289 } |
|
290 } |
|
291 return 0; |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CDialogsStore::NewDialogId |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 TDialogId CDialogsStore::NewDialogId() |
|
299 { |
|
300 if (iDialogIdCounter < KMaxDialogId) |
|
301 { |
|
302 iDialogIdCounter++; |
|
303 } |
|
304 else |
|
305 { |
|
306 iDialogIdCounter = KMinDialogId; |
|
307 } |
|
308 return iDialogIdCounter; |
|
309 } |
|
310 |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CDialogsStore::TransactionEnded |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 void CDialogsStore::TransactionEnded (TTransactionId aTransactionId, |
|
317 TInt aReason) |
|
318 { |
|
319 TSglQueIter<CSipDialogItem> iter(iList); |
|
320 for (CSipDialogItem* dialog = iter; dialog; dialog = iter++) |
|
321 { |
|
322 if (dialog->TransactionItems().HasItem(aTransactionId)) |
|
323 { |
|
324 dialog->EndTransaction(aTransactionId,aReason); |
|
325 } |
|
326 } |
|
327 } |