|
1 /* |
|
2 * Copyright (c) 2006-2009 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 * Name : CTransactionStore.h |
|
16 * Part of : TransactionUser |
|
17 * Version : SIP/6.0 |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 /** |
|
25 @internalComponent |
|
26 */ |
|
27 |
|
28 #ifndef CTRANSACTIONSTORE_H |
|
29 #define CTRANSACTIONSTORE_H |
|
30 |
|
31 // INCLUDES |
|
32 #include "SipStackServerDefs.h" |
|
33 |
|
34 #include "MTransactionStore.h" |
|
35 #include "MTransactionFinder.h" |
|
36 #include "TransactionInfo.h" |
|
37 |
|
38 #include <e32base.h> |
|
39 #include <stringpool.h> |
|
40 |
|
41 // FORWARD DECLARATIONS |
|
42 class CTransactionBase; |
|
43 |
|
44 class MTransactionOwner; |
|
45 class CUserAgent; |
|
46 class CUserAgentServer; |
|
47 class MTransactionHeaders; |
|
48 |
|
49 // CLASS DECLARATION |
|
50 |
|
51 /** |
|
52 * CTransactionStore contains the information of all existing transactions. |
|
53 * This information is used for e.g. routing the incoming SIP messages to the |
|
54 * correct transaction or UA. |
|
55 */ |
|
56 class CTransactionStore : |
|
57 public CBase, |
|
58 public MTransactionStore, |
|
59 public MTransactionFinder |
|
60 { |
|
61 public: // Constructors and destructor |
|
62 |
|
63 /** |
|
64 * Creates a new object. |
|
65 * @return New CTransactionStore object, ownership is transferred. |
|
66 */ |
|
67 static CTransactionStore* NewL(); |
|
68 |
|
69 ~CTransactionStore(); |
|
70 |
|
71 public: // From MTransactionStore |
|
72 |
|
73 TInt UpdateTransactionId(TTransactionId aOldTransactionId, |
|
74 TTransactionId aNewTransactionId); |
|
75 |
|
76 void Remove(TTransactionId aTransactionId); |
|
77 |
|
78 public: // From MTransactionFinder |
|
79 |
|
80 MReceiverObserver* Search(CSIPMessage& aMsg); |
|
81 |
|
82 void IcmpErrorL(const TInetAddr& aAddress, |
|
83 CSipConnectionMgr::TICMPError aError); |
|
84 |
|
85 public: // New functions |
|
86 |
|
87 /** |
|
88 * Generates a new unique value to be used as a TransactionId. |
|
89 * @return value New TransactionId value |
|
90 */ |
|
91 TTransactionId NewTransactionId(); |
|
92 |
|
93 /** |
|
94 * Stores information of a transaction. |
|
95 * @pre aUserAgent != NULL |
|
96 * @param aTransactionId transaction identifier |
|
97 * @param aUserAgent UA, ownership is transferred |
|
98 * @param aTransaction Transaction object, can be NULL. Ownership is not |
|
99 * transferred,. as UA owns aTransaction. |
|
100 * @param aMsg SIP message which initiated the transaction, can be NULL. |
|
101 * Ownership is not transferred. |
|
102 * @param aType Identifies which kind of transaction this is |
|
103 * (client, server, etc.) |
|
104 */ |
|
105 void AddL(TTransactionId aTransactionId, |
|
106 CUserAgent* aUserAgent, |
|
107 CTransactionBase* aTransaction, |
|
108 CSIPMessage* aMsg, |
|
109 CTransactionBase::TTransactionType aType); |
|
110 |
|
111 /** |
|
112 * Updates the information of the transaction identified by aTransactionId. |
|
113 * @pre Transaction must exist in the CTransactionStore |
|
114 * @param aTransactionId transaction identifier |
|
115 * @param aTransaction New value for the transaction pointer, can be NULL. |
|
116 * Ownership is not transferred. |
|
117 * @param aMsg The transaction related headers which are present in the |
|
118 * aMsg are copied to CTransactionStore. The possibly existing previously |
|
119 * stored headers discarded. This parameter can be NULL. Ownership is not |
|
120 * transferred. |
|
121 * @leave KErrNotFound If no such transaction is found |
|
122 */ |
|
123 void UpdateL(TTransactionId aTransactionId, |
|
124 CTransactionBase* aTransaction, |
|
125 CSIPMessage* aMsg); |
|
126 |
|
127 /** |
|
128 * Updates the To tag of the transaction identified by the aTransactionId. |
|
129 * @pre Transaction must exists in the CTransactionStore |
|
130 * @param aTransactionId transaction identifier |
|
131 * @param aTag To tag |
|
132 * @leave KErrNotFound If no such transaction is found |
|
133 */ |
|
134 void UpdateToTagL(TTransactionId aTransactionId, RStringF aTag); |
|
135 |
|
136 /** |
|
137 * Clears the pointer to UA by setting it NULL. |
|
138 * The UA is identified by aTransactionId. |
|
139 * @param aTransactionId Identifies the UA |
|
140 */ |
|
141 void ClearUserAgent(TTransactionId aTransactionId); |
|
142 |
|
143 /** |
|
144 * Clears the pointer to transaction by setting it NULL. Transaction is |
|
145 * identified by aTransactionId. |
|
146 * @param aTransactionId Identifies the transaction |
|
147 */ |
|
148 void ClearTransaction(TTransactionId aTransactionId); |
|
149 |
|
150 /** |
|
151 * Searches the store for an UAS to match the CANCEL. |
|
152 * @param aCancel IN: CANCEL request |
|
153 * @param aCancelUAS IN: UA that is searching for an UAS to be canceled. |
|
154 * TransactionStore checks aCancelUAS to avoid returning the same UAS |
|
155 * that is handling the CANCEL request. |
|
156 * @return UAS to be canceled, NULL if not found. Ownership isn't |
|
157 * transferred. |
|
158 */ |
|
159 CUserAgentServer* SearchUasToCancel(CSIPRequest& aCancel, |
|
160 const CUserAgent& aCancelUAS); |
|
161 |
|
162 /** |
|
163 * Searches the store for an UA having the specified aTransactionId. |
|
164 * @param aTransactionId Identifies the UA |
|
165 * @return The found UA or NULL if not found. Ownership is not transferred. |
|
166 */ |
|
167 CUserAgent* SearchById(TTransactionId aTransactionId); |
|
168 |
|
169 /** |
|
170 * Checks if the SIP request is a merged request. |
|
171 * Searches through the stored transactions for a transaction with a |
|
172 * matching From tag, Call-ID and CSeq. Skips the specified UA which is |
|
173 * aUserAgent requesting this search. |
|
174 * @param aUserAgent UA asking if the request is merged |
|
175 * @param aReq SIP request |
|
176 * @return ETrue if the request is merged, EFalse otherwise |
|
177 */ |
|
178 TBool IsMergedRequest(const CUserAgent& aUserAgent, CSIPRequest& aReq); |
|
179 |
|
180 /** |
|
181 * Copies any Record-Route headers possibly present in aReq, to the |
|
182 * specified transaction's stored information. |
|
183 * |
|
184 * @pre The transaction identified by aTransactionId must not already have |
|
185 * stored Record-Route headers. |
|
186 * @post |
|
187 * |
|
188 * @param aTransactionId Transaction id used for identifying the |
|
189 * transaction, which will store the Record-Route headers. |
|
190 * @param aReq SIP request from which the headers are copied from. |
|
191 */ |
|
192 void StoreRecordRouteHeadersL(TTransactionId aTransactionId, |
|
193 CSIPRequest& aReq); |
|
194 |
|
195 /** |
|
196 * Frees the stored Record-Route headers from the specified transaction. |
|
197 * @param aTransactionId Transaction id used for identifying the |
|
198 * transaction which the Record-Route headers are freed. |
|
199 */ |
|
200 void FreeRecordRouteHeaders(TTransactionId aTransactionId); |
|
201 |
|
202 /** |
|
203 * Copies any Contact headers possibly present in aReq, to the specified |
|
204 * transaction's stored information. |
|
205 * @pre The transaction identified by aTransactionId must not already have |
|
206 * stored Contact headers. |
|
207 * @param aTransactionId Transaction id used for identifying the |
|
208 * transaction which will store the Contact headers. |
|
209 * @param aReq SIP request from which the headers are copied from. |
|
210 */ |
|
211 void StoreContactHeadersL(TTransactionId aTransactionId, |
|
212 CSIPRequest& aReq); |
|
213 |
|
214 /** |
|
215 * Frees the stored Contact headers from the specified transaction. |
|
216 * @param aTransactionId Transaction id used for identifying the |
|
217 * transaction which the Contact headers are freed. |
|
218 */ |
|
219 void FreeContactHeaders(TTransactionId aTransactionId); |
|
220 |
|
221 /** |
|
222 * Copies certain headers from the CTransactionInfo item, identified by the |
|
223 * aTransactionId, to the response message (aResp). |
|
224 * @param aTransactionId Transaction id used for locating the correct |
|
225 * CTransactionInfo object |
|
226 * @param aResp IN/OUT: SIP response message which will be filled. |
|
227 */ |
|
228 void CopyHeadersToResponseL(TTransactionId aTransactionId, |
|
229 CSIPResponse& aResp); |
|
230 |
|
231 /** |
|
232 * Copies certain headers from the CTransactionInfo item, identified by the |
|
233 * aTransactionId, to the aReq. |
|
234 * @param aTransactionId Transaction id used for locating the |
|
235 * CTransactionInfo object from which the headers are copied from. |
|
236 * @param aReq SIP request into which the headers are copied |
|
237 * @param aCopyRequestURI ETrue: Request-URI is copied, EFalse: otherwise |
|
238 * @param aCopyViaHeaders ETrue: Via headers are copied, EFalse: otherwise |
|
239 */ |
|
240 void CopyHeadersToRequestL(TTransactionId aTransactionId, |
|
241 CSIPRequest& aReq, |
|
242 TBool aCopyRequestURI, |
|
243 TBool aCopyViaHeaders); |
|
244 |
|
245 /** |
|
246 * Retrieve the transaction related headers of the SIP message that created |
|
247 * the transaction. |
|
248 * @param aTransactionId Identifies the transaction whose SIP headers are |
|
249 * requested. |
|
250 * @return MTransactionHeaders* Object containing the SIP headers. |
|
251 * Ownership is transferred. NULL if the transaction was not found. |
|
252 */ |
|
253 MTransactionHeaders* TransactionHeadersL(TTransactionId aTransactionId); |
|
254 |
|
255 /** |
|
256 * Obtains information from one transaction (not from any specific |
|
257 * transaction). This information will be as a input to generate random |
|
258 * tags. |
|
259 * @param aTransactionId Will be filled by a transactionId value, unless |
|
260 * there are no stored transactions. |
|
261 * @param aUserAgent OUT: Will be set to point to a UA object. |
|
262 * If there are no stored UAs, this pointer isn't set. |
|
263 * Ownership isn't transferred. |
|
264 * @param aMsg OUT: Pointer to a SIP Message, might be zero if no SIP |
|
265 * message was available. Ownership is transferred. |
|
266 */ |
|
267 void RandomTaInfoL(TTransactionId& aTaId, |
|
268 CUserAgent** aUserAgent, |
|
269 CSIPMessage** aMsg); |
|
270 |
|
271 /** |
|
272 * Returns the request method of the transaction identified by |
|
273 * aTransactionId. |
|
274 * @pre A transaction identified by aTransactionId must exist in the store. |
|
275 * @param aTransactionId TransactionId |
|
276 * @return Request method |
|
277 */ |
|
278 RStringF RequestMethod(TTransactionId aTransactionId); |
|
279 |
|
280 /** |
|
281 * Clears the MTransactionOwner pointers from the stored UA objects, which |
|
282 * have a matching MTransactionOwner callback. |
|
283 * @pre aObserver != NULL |
|
284 * @param aObserver pointer to the MTransactionOwner callback. Ownership |
|
285 * isn't transferred. |
|
286 * @return KErrNone if successful, KErrNotFound if no UA used the specified |
|
287 * aObserver callback. |
|
288 */ |
|
289 TInt ClearTransactionOwner(const MTransactionOwner* aObserver); |
|
290 |
|
291 /** |
|
292 * Goes through all stored transactions using the given IAP-id and those |
|
293 * which are currently resolving the remote address, are stopped. |
|
294 * @param aIapId IAP-id |
|
295 * @param aReason Reason why transaction is stopped |
|
296 */ |
|
297 void EndResolvingTransactions(TUint32 aIapId, TInt aReason); |
|
298 |
|
299 /** |
|
300 * Delete any transactions matching the IAP-id. |
|
301 * @param aIapId IAP-id |
|
302 */ |
|
303 void RemoveItemsByIapId(TUint32 aIapId); |
|
304 |
|
305 /** |
|
306 * Check if there is space for a new server transaction. |
|
307 * @return ETrue New server transaction can be created |
|
308 * EFalse otherwise |
|
309 */ |
|
310 TBool AllowMoreServerTransactions() const; |
|
311 private: // New functions, for internal use |
|
312 void ConstructL(); |
|
313 CTransactionStore(); |
|
314 |
|
315 /** |
|
316 * Removes aItem from the list, deletes aItem's contents and the aItem. |
|
317 * @pre aItem != NULL |
|
318 * @param aItem Item to delete. |
|
319 */ |
|
320 void DeleteItem(CTransactionInfo* aItem); |
|
321 |
|
322 /** |
|
323 * Searches the store for a CTransactionInfo item of the transaction with |
|
324 * the given aTransactionId. |
|
325 * @param aTransactionId identifies the transaction whose information is |
|
326 * searched for |
|
327 * @return Pointer to the object containing transaction's information, |
|
328 * NULL if no such transaction is found. Ownership isn't transferred. |
|
329 */ |
|
330 CTransactionInfo* FindTransactionInfo(TTransactionId aTransactionId); |
|
331 |
|
332 /** |
|
333 * Searches the store for an object which should receive a SIP message |
|
334 * with the Branch-ID, Sent-by value and method given as parameters. |
|
335 * Transaction type has to also match. |
|
336 * @param aMsg SIP message received from remote endpoint |
|
337 * @param aType identifies which kind of transaction this is |
|
338 * (client, server, etc.) |
|
339 * @param aUserAgent IN: If non-zero: this is the UA that searches for an |
|
340 * UAS to be canceled. If NULL: the search is done to find a transaction |
|
341 * to receive an incoming SIP message. Ownership isn't transferred. |
|
342 * @return Pointer to the receiving interface of the object which should |
|
343 * receive the SIP message (the actual object can UA or transaction). |
|
344 * NULL if not found. Ownership is not transferred. |
|
345 */ |
|
346 MReceiverObserver* SearchByBranch(CSIPMessage& aMsg, |
|
347 CTransactionBase::TTransactionType aType, |
|
348 const CUserAgent* aUserAgent); |
|
349 |
|
350 /** |
|
351 * Searches the store for an object which should receive the SIP request, |
|
352 * using the To, From, CallID, CSeq, topmost Via, Request-URI. |
|
353 * Transaction type has to also match. Via Branch is not used for matching. |
|
354 * @param aReq SIP request received from remote endpoint |
|
355 * @param aType identifies which kind of transaction this is |
|
356 * @param aUserAgent IN: If non-NULL: the UA which is searching for an UAS |
|
357 * to be canceled. If NULL: the search is done to find a transaction to |
|
358 * receive an incoming SIP message. Ownership isn't transferred. |
|
359 * @return Receiving interface of the object which should receive the |
|
360 * request (the actual object can UA or transaction). NULL if no matching |
|
361 * object was found. Ownership isn't transferred. |
|
362 */ |
|
363 MReceiverObserver* |
|
364 SearchServerByHeaders(CSIPRequest& aReq, |
|
365 CTransactionBase::TTransactionType aType, |
|
366 const CUserAgent* aUserAgent); |
|
367 |
|
368 /** |
|
369 * Check if all of the required headers for Transaction matching are |
|
370 * present in the SIP message. |
|
371 * @param aMsg SIP message |
|
372 * @return ETrue if all required headers exist, EFalse otherwise. |
|
373 */ |
|
374 TBool RequiredHeadersPresent(CSIPMessage& aMsg) const; |
|
375 |
|
376 /** |
|
377 * Compares the TTransactionType stored in aInfo with aType. |
|
378 * @param aInfo Transaction information |
|
379 * @param aType Transaction type |
|
380 * @param aSearchCanceledUas Indicates whether the comparison is performed |
|
381 * for searching an UAS to be canceled. |
|
382 * @return ETrue if transaction types match, EFalse otherwise |
|
383 */ |
|
384 TBool CompareTransactionTypes(const CTransactionInfo& aInfo, |
|
385 CTransactionBase::TTransactionType aType, |
|
386 TBool aSearchCanceledUas) const; |
|
387 |
|
388 /** |
|
389 * This function is used to return the receiver interface of the |
|
390 * transaction/UA that should be given the SIP message received from the |
|
391 * network. |
|
392 * If the SIP message is ACK and the UA, pointed by aInfo, has sent a 2xx |
|
393 * response, the transaction/UA is ignored as Via Branch must not be used |
|
394 * to find the transaction in case of ACK to a 2xx. |
|
395 * @param aMsg SIP message received from network. |
|
396 * @param aInfo Information of the transaction that should receive a |
|
397 * SIP message received from network. aInfo has been determined by an |
|
398 * earlier search among the existing transactions. |
|
399 * @param aUserAgent If NULL, this parameter is ignored. If UA is not NULL, |
|
400 * it is the UA that is searching for an UAS to be canceled. Used to the |
|
401 * avoid returning the MReceiverObserver interface of the same UAS that |
|
402 * initiated the search. Ownership isn't transferred. |
|
403 * @return Object where the SIP message received from network should be |
|
404 * passed next or NULL if there is no suitable object. Ownership is not |
|
405 * transferred. |
|
406 */ |
|
407 MReceiverObserver* IgnoreAckTo2xx(const CSIPMessage& aMsg, |
|
408 CTransactionInfo& aInfo, |
|
409 const CUserAgent* aUserAgent) const; |
|
410 |
|
411 /** |
|
412 * This function is used to return the receiver interface of the |
|
413 * transaction/UA that should be given the SIP message received from the |
|
414 * network. |
|
415 * @param aInfo Information of the transaction that should receive a |
|
416 * SIP message received from network. aInfo has been determined by an |
|
417 * earlier search among the existing transactions. |
|
418 * @param aUserAgent If NULL, this parameter is ignored. If UA is not NULL, |
|
419 * it is the UA that is searching for an UAS to be canceled. Used to the |
|
420 * avoid returning the MReceiverObserver interface of the same UAS that |
|
421 * initiated the search. Ownership isn't transferred. |
|
422 * @return Object where the SIP message received from network should be |
|
423 * passed next or NULL if there is no suitable object. Ownership is not |
|
424 * transferred. |
|
425 */ |
|
426 MReceiverObserver* CheckResult(CTransactionInfo& aInfo, |
|
427 const CUserAgent* aUserAgent) const; |
|
428 |
|
429 /** |
|
430 * Remove item from list of transactions. |
|
431 * @param aItem Item to remove |
|
432 */ |
|
433 void RemoveListItem(CTransactionInfo& aItem); |
|
434 private: // Data |
|
435 |
|
436 // Information of all existing UAs and transactions |
|
437 TSglQue<CTransactionInfo> iList; |
|
438 |
|
439 // Counter for generating unique numbers to be used as TransactionIds. |
|
440 // This will eventually wrap around, but by the time that happens, it is |
|
441 // expected the old transactions using the same TransactionId values have |
|
442 // been terminated. |
|
443 TTransactionId iTransactionIdCounter; |
|
444 // Amount of UAS / server transactions in iList |
|
445 TInt iServerTransactionCount; |
|
446 // Maximum amount of UAS / server transactions in iList |
|
447 TInt iMaxServerTransactions; |
|
448 |
|
449 // We don't use __DECLARE_TEST because we don't want to export this function. |
|
450 void __DbgTestInvariant() const; |
|
451 |
|
452 |
|
453 |
|
454 #ifdef CPPUNIT_TEST |
|
455 friend class CTransactionStore_Test; |
|
456 friend class CTransactionUser_Test; |
|
457 friend class CNormalUAC_ResolveAddress_Test; |
|
458 friend class CNormalUAC_WaitResponse_Test; |
|
459 friend class CUserAgentServer_Test; |
|
460 friend class CUserAgentClient_Test; |
|
461 #endif |
|
462 }; |
|
463 |
|
464 #endif // end of CTRANSACTIONSTORE_H |
|
465 |
|
466 // End of File |