|
1 /* |
|
2 * Copyright (c) 2005-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 : RegBindingImplementation.h |
|
16 * Part of : SIP Client |
|
17 * Interface : SDK API, SIP Client API |
|
18 * Version : 1.0 |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 /** |
|
26 @internalComponent |
|
27 */ |
|
28 |
|
29 #ifndef CREGBINDINGIMPLEMENTATION_H |
|
30 #define CREGBINDINGIMPLEMENTATION_H |
|
31 |
|
32 // INCLUDES |
|
33 #include <stringpool.h> |
|
34 #include "sipregistrationcontext.h" |
|
35 #include "transactionassociation.h" |
|
36 #include "siprefreshassociation.h" |
|
37 #include "_sipcodecdefs.h" |
|
38 |
|
39 // FORWARD DECLARATIONS |
|
40 class CSIPRegistrationBinding; |
|
41 class CSIPResponseElements; |
|
42 class CSIPContactHeader; |
|
43 class CSIPRouteHeader; |
|
44 class CUri8; |
|
45 class CRegistrationState; |
|
46 class CSIPToHeader; |
|
47 class CSIPFromHeader; |
|
48 class CConnectionCallback; |
|
49 |
|
50 |
|
51 // CLASS DECLARATION |
|
52 |
|
53 /** |
|
54 * Implementation class for managing SIP registration binding. |
|
55 */ |
|
56 class CRegBindingImplementation : |
|
57 public CBase, |
|
58 public MSIPRegistrationContext, |
|
59 public MTransactionAssociation, |
|
60 public MSIPRefreshAssociation |
|
61 { |
|
62 public: // Constructors and destructor |
|
63 |
|
64 /** |
|
65 * Two-phased constructor. |
|
66 * @pre aAor != 0 && |
|
67 * aContact != 0 |
|
68 * @pre "Expires" parameter in aContact must be >= KSIPMinExpirationValue |
|
69 * @param aRegistration Registration binding who creates this |
|
70 * CRegBindingImplementation instance. |
|
71 * @param aConnection The SIP connection to be used |
|
72 * @param aAor contains user's address-of-record to register; |
|
73 * the ownership is transfered |
|
74 * @param aContact contact(s) to be registered. The "expires" parameter |
|
75 * indicates how long the client would like the binding to be |
|
76 * valid. |
|
77 * "expires" parameter value must be >= KSIPMinExpirationValue; |
|
78 * the ownership is transfered |
|
79 * @param aRefresh if set, created binding will be refreshed; |
|
80 * the ownership is transfered |
|
81 * @param aOutboundProxy an outbound proxy address; |
|
82 * the ownership is transfered |
|
83 * @param aRemoteUri if set, will be used in request-uri construction; |
|
84 * the ownership is transfered |
|
85 * @param aFrom From header, the ownership is transferred |
|
86 * @return New object, ownership is transferred. |
|
87 */ |
|
88 static CRegBindingImplementation* |
|
89 NewL(CSIPRegistrationBinding& aRegistration, |
|
90 CSIPConnection& aConnection, |
|
91 CSIPToHeader* aAor, |
|
92 CSIPContactHeader* aContact, |
|
93 CSIPRefresh* aRefresh, |
|
94 CSIPRouteHeader* aOutboundProxy, |
|
95 CUri8* aRemoteUri, |
|
96 CSIPFromHeader* aFrom); |
|
97 |
|
98 /** |
|
99 * Destructor |
|
100 */ |
|
101 ~CRegBindingImplementation(); |
|
102 |
|
103 public: // From MSIPRegistrationContext |
|
104 |
|
105 /** |
|
106 * Checks if the registration context can be |
|
107 * used for creating SIP messages/dialogs |
|
108 * @return ETrue if the registration binding exists; EFalse |
|
109 * otherwise |
|
110 */ |
|
111 TBool IsContextActive() const; |
|
112 |
|
113 /** |
|
114 * Gets the context id |
|
115 * @return context id |
|
116 * For internal use only |
|
117 */ |
|
118 TUint32 ContextId() const; |
|
119 |
|
120 public: // From MTransactionAssociation |
|
121 |
|
122 CSIPClientConnection& ClientConnectionL(); |
|
123 |
|
124 CSIPClientConnection* ClientConnection(); |
|
125 |
|
126 CSIPConnection& SIPConnectionL(); |
|
127 |
|
128 void AddTransactionL(CSIPTransactionBase& aTransaction); |
|
129 |
|
130 void RemoveTransaction(const CSIPTransactionBase& aTransaction); |
|
131 |
|
132 public: // From MSIPRefreshAssociation |
|
133 |
|
134 CSIPClientTransaction* |
|
135 UpdateRefreshL(CSIPRefresh& aRefresh, |
|
136 CSIPMessageElements* aElements, |
|
137 TBool aTerminate); |
|
138 |
|
139 void DeletingRefresh(CSIPRefresh& aRefresh, TUint32 aRefreshId); |
|
140 |
|
141 MTransactionAssociation& TransactionAssociation(); |
|
142 |
|
143 TInt CheckIfStandAlone(); |
|
144 |
|
145 public: // New functions |
|
146 |
|
147 /** |
|
148 * Creates SIP REGISTER request, sends it to the given destination. |
|
149 * Received 2xx response will create at least one registration |
|
150 * binding. |
|
151 * @pre Connection().State()==EActive |
|
152 * @param aElements contains user SIP headers and content; the ownership |
|
153 * is taken |
|
154 * @return SIP REGISTER transaction; the ownership is transfered |
|
155 * @leave KErrSIPMalformedMessage if aElements contain contact or |
|
156 * expires headers |
|
157 */ |
|
158 CSIPClientTransaction* RegisterL(CSIPMessageElements* aElements=0); |
|
159 |
|
160 /** |
|
161 * Creates SIP (de)REGISTER request, sends it to the given destination. |
|
162 * This function will remove registration binding. |
|
163 * Any SIP response (2xx - 6xx) to this request removes the binding. |
|
164 * Note that deregistration can be done then the 2xx is received to the |
|
165 * initial REGISTER transaction and there is no on-going registration |
|
166 * updates. |
|
167 * @pre Connection().State()==EActive |
|
168 * @param aElements contains user SIP headers and content; the ownership |
|
169 * is transfered. If set, user SIP headers must not contain any |
|
170 * Contact-header nor Expires-header |
|
171 * @return SIP REGISTER transaction; the ownership is transfered |
|
172 */ |
|
173 CSIPClientTransaction* DeregisterL(CSIPMessageElements* aElements=0); |
|
174 |
|
175 CSIPClientTransaction* |
|
176 UpdateL(CSIPMessageElements* aElements, TUint* aExpirationValue=0); |
|
177 |
|
178 /** |
|
179 * Gets the SIP connection used for the registration. |
|
180 * @return SIP connection used for the registration, or 0-pointer if the |
|
181 * connection has been deleted. Ownership is not transferred. |
|
182 */ |
|
183 CSIPConnection* Connection(); |
|
184 |
|
185 /** |
|
186 * Gets the SIP connection used for the registration. |
|
187 * @return SIP connection used for the registration, or 0-pointer if the |
|
188 * connection has been deleted. Ownership is not transferred. |
|
189 */ |
|
190 const CSIPConnection* Connection() const; |
|
191 |
|
192 /** |
|
193 * Sets/resets outbound proxy. |
|
194 * If a 0-pointer is given the outbound proxy will be reset. |
|
195 * @param aOutboundProxy an outbound proxy. Ownership is transferred. |
|
196 */ |
|
197 void SetOutboundProxyL(CSIPRouteHeader* aOutboundProxy); |
|
198 |
|
199 /** |
|
200 * Gets the address-of-record (AOR) used for creating binding |
|
201 * @return address-of-record (AOR) |
|
202 */ |
|
203 const CSIPToHeader& Aor() const; |
|
204 |
|
205 /** |
|
206 * Gets Contact header associated with the registration binding |
|
207 * @return Contact header |
|
208 */ |
|
209 const CSIPContactHeader& ContactHeader() const; |
|
210 |
|
211 /** |
|
212 * Gets Contact header associated with the registration binding |
|
213 * @return Contact header |
|
214 */ |
|
215 CSIPContactHeader& ContactHeader(); |
|
216 |
|
217 /** |
|
218 * Gets the registered Contact-header received in the 200 OK response. |
|
219 * @return Contact header, or NULL if IsContextActive() is EFalse. |
|
220 * Ownership is not transferred. |
|
221 */ |
|
222 const CSIPContactHeader* RegisteredContact() const; |
|
223 |
|
224 /** |
|
225 * Gets used outbound proxy |
|
226 * @return outbound proxy or a 0-pointer if not set. Ownership is not |
|
227 * transferred. |
|
228 */ |
|
229 const CSIPRouteHeader* OutboundProxy() const; |
|
230 |
|
231 /** |
|
232 * Gets associated refresh in case the user has requested the refresh of |
|
233 * the registration. Note that client cannot use update or terminate |
|
234 * functions defined in the CSIPRefresh class. |
|
235 * @return Associated refresh or a 0-pointer if the user has not |
|
236 * requested a refresh of registration binding. Ownership is not |
|
237 * transferred. |
|
238 */ |
|
239 const CSIPRefresh* SIPRefresh() const; |
|
240 |
|
241 /** |
|
242 * Gets associated refresh in case the user has requested the refresh of |
|
243 * the registration. Note that client cannot use update or terminate |
|
244 * functions defined in the CSIPRefresh class. |
|
245 * @return Associated refresh or a 0-pointer if the user has not |
|
246 * requested a refresh of registration binding. Ownership is not |
|
247 * transferred. |
|
248 */ |
|
249 CSIPRefresh* SIPRefresh(); |
|
250 |
|
251 /** |
|
252 * Compares this object to another object |
|
253 * @param aRegistration CRegBindingImplementation object to compare |
|
254 * @return ETrue if the objects are equal, otherwise EFalse |
|
255 */ |
|
256 TBool operator==(const CRegBindingImplementation& aRegistration) const; |
|
257 |
|
258 CSIPClientTransaction* DoRegisterL(CSIPMessageElements* aElements); |
|
259 |
|
260 CSIPClientTransaction* DoDeregisterL(CSIPMessageElements* aElements); |
|
261 |
|
262 CSIPClientTransaction* DoUpdateL(CSIPMessageElements* aElements, |
|
263 TUint* aExpirationValue); |
|
264 |
|
265 TBool IncomingResponseL(CSIPResponseElements* aElements, |
|
266 TUint32 aRequestId, |
|
267 TUint32 aRegistrationId, |
|
268 TUint32 aRefreshId, |
|
269 CConnectionCallback& aCallback); |
|
270 |
|
271 TBool ErrorOccured(TInt aError, |
|
272 TUint32 aRequestId, |
|
273 CConnectionCallback& aCallback); |
|
274 |
|
275 void SetRegistrationId(TUint32 aRegistrationId); |
|
276 |
|
277 /** |
|
278 * Searches for a transaction matching the given aRequestId. |
|
279 * |
|
280 * @param aRequestId Request id |
|
281 * @return Transaction object, or NULL if not found. Ownership isn't |
|
282 * transferred. |
|
283 */ |
|
284 CSIPClientTransaction* FindTransaction(TUint32 aRequestId); |
|
285 |
|
286 /** |
|
287 * Change the registration binding state. |
|
288 * |
|
289 * @param aNewState State to enter, can be NULL. |
|
290 * Ownership is not transferred. |
|
291 */ |
|
292 void ChangeState(const CRegistrationState* aNewState); |
|
293 |
|
294 void UpdateRefreshState(TUint aStatusCode) const; |
|
295 |
|
296 void ConnectionLost(); |
|
297 |
|
298 CSIPClientTransaction* CreateClientTransactionL(); |
|
299 |
|
300 TBool HandleError(CConnectionCallback& aCallback, |
|
301 TInt aError, |
|
302 TUint32 aRequestId, |
|
303 const CRegistrationState& aUnregistered); |
|
304 |
|
305 /** |
|
306 * Informs CRegBindingImplementation that the associated CSIPConnection |
|
307 * has been deleted. After this the CSIPRegistrationBinding object can't |
|
308 * be used any more. |
|
309 */ |
|
310 void ConnectionDeleted(); |
|
311 |
|
312 CSIPRegistrationBinding& Binding() const; |
|
313 |
|
314 void UpdateRegisteredContactL(); |
|
315 |
|
316 void RemoveRegisteredContact(); |
|
317 |
|
318 /** |
|
319 * Sets/resets properties. |
|
320 * @pre IsContextActive()==EFalse |
|
321 * @param aProperty. Property name |
|
322 * @param aValue. Property value |
|
323 * @leave KErrSIPInvalidRegistrationState if IsContextActive() is ETrue |
|
324 * @leave KErrNotFound if property is not found |
|
325 */ |
|
326 void SetPropertyL(TUint32 aProperty,TBool aValue); |
|
327 |
|
328 private: // Constructors, for internal use |
|
329 |
|
330 CRegBindingImplementation(CSIPRegistrationBinding& aRegistration, |
|
331 CSIPConnection& aConnection); |
|
332 |
|
333 void ConstructL(CSIPToHeader* aAor, |
|
334 CSIPContactHeader* aContacts, |
|
335 CSIPRefresh* aRefresh, |
|
336 CSIPRouteHeader* aOutboundProxy, |
|
337 CUri8* aRemoteUri, |
|
338 CSIPFromHeader* aFrom); |
|
339 |
|
340 private: // New functions, for internal use |
|
341 |
|
342 /** |
|
343 * Checks that CSIPConnection is available for use (not NULL). If |
|
344 * iConnection is NULL, it means user has deleted a resource needed by |
|
345 * CRegBindingImplementation, and this function leaves. |
|
346 */ |
|
347 void CheckConnectionL() const; |
|
348 |
|
349 /** |
|
350 * Returns the current registration state. If state handler is not |
|
351 * available, meaning user has deleted a resource needed by |
|
352 * CRegBindingImplementation, this function leaves. |
|
353 */ |
|
354 const CRegistrationState& StateL() const; |
|
355 |
|
356 /** |
|
357 * Checks that aElements don't contain Contact or Expires headers. |
|
358 * @param aElements Message elements |
|
359 * @leave KErrSIPMalformedMessage If Contact or Expires header is |
|
360 * present in aElements. |
|
361 */ |
|
362 void CheckElementsL(const CSIPMessageElements* aElements) const; |
|
363 |
|
364 /** |
|
365 * Removes, does not delete, Contact headers from aElements. |
|
366 * @pre aElements != NULL |
|
367 * @param aElements Message elements. Ownership is not transferred. |
|
368 */ |
|
369 static void DetachContactHeader(TAny* aElements); |
|
370 |
|
371 /** |
|
372 * Removes, does not delete, the headers identified by aName, from |
|
373 * aElements. |
|
374 * @pre aElements != NULL |
|
375 * @param aElements Message elements. Ownership is not transferred. |
|
376 * @param aName Header name |
|
377 */ |
|
378 static void DetachHeaders(TAny* aElements, RStringF aName); |
|
379 |
|
380 private: // Data |
|
381 |
|
382 //Registration binding who owns this CRegBindingImplementation instance |
|
383 CSIPRegistrationBinding& iRegistration; |
|
384 |
|
385 //The used connection. CRegBindingImplementation doesn't own it. |
|
386 //If this pointer is NULL; it means application has deleted the |
|
387 //connection before deleting the CRegBindingImplementation, and this |
|
388 //CRegBindingImplementation is now useless. |
|
389 CSIPConnection* iConnection; |
|
390 |
|
391 //Outbound proxy or NULL if no proxy is specified. Owned. |
|
392 CSIPRouteHeader* iOutboundProxy; |
|
393 |
|
394 CSIPToHeader* iAor; //Owned. |
|
395 CSIPFromHeader* iFrom; //Owned, can be NULL. |
|
396 CSIPContactHeader* iContact; //Owned |
|
397 |
|
398 CSIPContactHeader* iRegisteredContact; //Owned, can be NULL |
|
399 |
|
400 CUri8* iRemoteUri; //Owned, can be NULL. |
|
401 |
|
402 |
|
403 //CRegBindingImplementation owns the CSIPRefresh object. It is not |
|
404 //deleted even the refresh ends since user can try to register again, |
|
405 //using the same CRegBindingImplementation (and CSIPRefresh) instance. |
|
406 //CRegBindingImplementation can have maximum of one refresh object |
|
407 CSIPRefresh* iRefresh; |
|
408 |
|
409 //Id received from SIP client |
|
410 TUint32 iRegistrationId; |
|
411 |
|
412 //Only client transactions can be bound to registration. Transactions |
|
413 //are not owned. Application owns them. |
|
414 RPointerArray<CSIPClientTransaction> iTransactions; |
|
415 |
|
416 //Current state of the registration. CRegBindingImplementation doesn't |
|
417 //own the state object. If iState is NULL, it means the CSIP owning the |
|
418 //registration states has been deleted. |
|
419 const CRegistrationState* iState; |
|
420 |
|
421 TBool iSendWithExpires; |
|
422 TBool iCacheOutboundProxyIP; |
|
423 |
|
424 private: // For testing purposes |
|
425 |
|
426 UNIT_TEST(CSIP_Test) |
|
427 UNIT_TEST(CSIPRegistrationBinding_Test) |
|
428 UNIT_TEST(CSIPInviteDialogAssoc_Test) |
|
429 UNIT_TEST(CSIPSubscribeDialogAssoc_Test) |
|
430 UNIT_TEST(CSIPReferDialogAssoc_Test) |
|
431 |
|
432 void __DbgTestInvariant() const; |
|
433 |
|
434 }; |
|
435 |
|
436 #endif |