2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Name : sipsubscribedialogassoc.h
16 * Part of : SIP Client
17 * Interface : SDK API, SIP Client API
24 #ifndef CSIPSUBSCRIBEDIALOGASSOC_H
25 #define CSIPSUBSCRIBEDIALOGASSOC_H
28 #include "sipdialogassocbase.h"
32 // FORWARD DECLARATIONS
36 class CSIPContactHeader;
37 class CSIPEventHeader;
38 class CSIPMessageElements;
39 class MSIPRegistrationContext;
48 * Class for managing SIP SUBSCRIBE dialog associations.
49 * It provides services for creating, using and terminating SIP SUBSCRIBE
50 * dialog associations. The client can have multiple SUBSRIBE dialog
51 * associations per same SIP dialog.
52 * Implementation handles SUBSCRIBE on the dialog level defined by Call-Id,
53 * local and remote tags; "Event" header semantics are client's responsibility
57 class CSIPSubscribeDialogAssoc : public CSIPDialogAssocBase
59 public: // Constructors and destructor
61 * Two-phased constructor.
62 * Should be used if response to the SIP request to be sent
63 * will create a SIP dialog association.
65 * @param aDialog a dialog to be associated with
66 * @param aEvent an event to subscribe to; the ownership is transferred
67 * @return New object; the ownership is transferred
68 * @leave KErrArgument if aEvent == 0
69 * @leave KErrSIPResourceNotAvailable if a required SIP Client API
70 * object has been deleted
72 IMPORT_C static CSIPSubscribeDialogAssoc*
73 NewL(CSIPDialog& aDialog,
74 CSIPEventHeader* aEvent);
77 * Two-phased constructor.
78 * Must be used if response to the SIP request to be sent
79 * will create a SIP dialog association.
80 * @param aDialog a dialog to be associated with
81 * @param aEvent an event to subscribe to; the ownership is transferred
82 * @return New object, ownership is transferred
83 * @leave KErrArgument if aEvent == 0
84 * @leave KErrSIPResourceNotAvailable if a required SIP Client API
85 * object has been deleted
87 IMPORT_C static CSIPSubscribeDialogAssoc*
88 NewLC(CSIPDialog& aDialog,
89 CSIPEventHeader* aEvent);
92 * Two-phased constructor
94 * @pre aRemoteUri != 0
96 * The user of the class must not define tags in From-header and
98 * @param aConnection a SIP connection to be used with
100 * @param aFrom originator's address; the ownership is transfered
101 * @param aRemoteUri a remote target URI that identifies a resource that
102 * the request is addressed to.
103 * @param aEvent an event to subscribe to; the ownership is transferred
104 * @param aTo logical recipient's address; if not defined
105 * the remote target uri will be used for To-header
106 * construction; the ownership is transfered
107 * @param aContact a contact to be used in dialog creation. Must be
108 * given only if user intends to re-direct future requests;
109 * the ownership is transfered
110 * @return New object; the ownership is transferred.
111 * @leave KErrArgument if aFrom == 0, aRemoteUri == 0 or aEvent == 0
112 * @leave KErrSIPResourceNotAvailable if a required SIP Client API
113 * object has been deleted
115 IMPORT_C static CSIPSubscribeDialogAssoc*
116 NewL(CSIPConnection& aConnection,
117 CSIPFromHeader* aFrom,
119 CSIPEventHeader* aEvent,
121 CSIPContactHeader* aContact=0);
124 * Two-phased constructor
126 * @pre aRemoteUri != 0
128 * The user of the class must not define tags in From-header and
130 * @param aConnection a SIP connection to be used with
132 * @param aFrom originator's address; the ownership is transfered
133 * @param aRemoteUri a remote target URI that identifies a resource that
134 * the request is addressed to.
135 * @param aEvent an event to subscribe to; the ownership is transferred
136 * @param aTo logical recipient's address; if not defined
137 * the remote target uri will be used for To-header
138 * construction; the ownership is transfered
139 * @param aContact a contact to be used in dialog creation. Must be
140 * given only if user intends to re-direct future requests;
141 * the ownership is transfered
142 * @return New object; the ownership is transferred.
143 * @leave KErrArgument if aFrom == 0, aRemoteUri == 0 or aEvent == 0
144 * @leave KErrSIPResourceNotAvailable if a required SIP Client API
145 * object has been deleted
147 IMPORT_C static CSIPSubscribeDialogAssoc*
148 NewLC(CSIPConnection& aConnection,
149 CSIPFromHeader* aFrom,
151 CSIPEventHeader* aEvent,
152 CSIPToHeader* aTo =0,
153 CSIPContactHeader* aContact=0);
156 * Two-phased constructor
157 * @pre aRemoteUri != 0
159 * The user of the class must not define tags in From-header
161 * @pre aContext.IsContextActive()==ETrue
162 * @param aConnection a SIP connection to be used with
164 * @param aRemoteUri a remote target URI that identifies a resource that
165 * the request is targeted to.
166 * @param aContext used for selecting outbound
167 * proxy and originator's address (AOR) and contact
168 * @param aEvent an event to subscribe to; the ownership is transferred
169 * @param aFrom originator's address. If not defined it will be
170 * constructed using registration context (User's AOR);
171 * the ownership is transfered
172 * @param aTo logical recipient's address; if not defined
173 * the remote target uri will be used for To-header
174 * construction; the ownership is transfered
175 * @param aContact a contact to be used in dialog creation. Must be
176 * given only if user intends to re-direct future requests;
177 * the ownership is transfered
178 * @return New object; the ownership is transferred.
179 * @leave KErrArgument if aRemoteUri == 0 or aEvent == 0
180 * @leave KErrSIPInvalidRegistrationState
181 * if aContext.IsContextActive()==EFalse
182 * @leave KErrSIPResourceNotAvailable if a required SIP Client API
183 * object has been deleted
185 IMPORT_C static CSIPSubscribeDialogAssoc*
186 NewL(CSIPConnection& aConnection,
188 const MSIPRegistrationContext& aContext,
189 CSIPEventHeader* aEvent,
190 CSIPFromHeader* aFrom = 0,
191 CSIPToHeader* aTo = 0,
192 CSIPContactHeader* aContact = 0);
195 * Two-phased constructor
196 * @pre aRemoteUri != 0
198 * The user of the class must not define tags in From-header
200 * @pre aContext.IsContextActive()==ETrue
201 * @param aConnection a SIP connection to be used with
203 * @param aRemoteUri a remote target URI that identifies a resource that
204 * the request is targeted to.
205 * @param aContext used for selecting outbound
206 * proxy and originator's address (AOR) and contact
207 * @param aEvent an event to subscribe to; the ownership is transferred
208 * @param aFrom originator's address. If not defined it will be
209 * constructed using registration context (User's AOR);
210 * the ownership is transfered
211 * @param aTo logical recipient's address; if not defined
212 * the remote target uri will be used for To-header
213 * construction; the ownership is transfered
214 * @param aContact a contact to be used in dialog creation. Must be
215 * given only if user intends to re-direct future requests;
216 * the ownership is transfered
217 * @return New object; the ownership is transferred.
218 * @leave KErrArgument if aRemoteUri == 0 or aEvent == 0
219 * @leave KErrSIPInvalidRegistrationState
220 * if aContext.IsContextActive()==EFalse
221 * @leave KErrSIPResourceNotAvailable if a required SIP Client API
222 * object has been deleted
224 IMPORT_C static CSIPSubscribeDialogAssoc*
225 NewLC(CSIPConnection& aConnection,
227 const MSIPRegistrationContext& aContext,
228 CSIPEventHeader* aEvent,
229 CSIPFromHeader* aFrom = 0,
230 CSIPToHeader* aTo = 0,
231 CSIPContactHeader* aContact = 0);
236 IMPORT_C ~CSIPSubscribeDialogAssoc();
238 public: //New functions
240 * Creates SUBSCRIBE and sends it to the remote target.
241 * 101-199 or 2xx response to SUBSCRIBE will create a dialog association
242 * in case of the first SUBSCRIBE request within this dialog.
243 * Client must not provide Event-header in the optional message headers.
245 * @pre Dialog().Connection().State()==EActive
246 * @pre Dialog().State()==CSIPDialog::EInit ||
247 * Dialog().State()==CSIPDialog::EConfirmed
248 * @param aElements optional SIP message headers and body. Ownership is
250 * @param aRefresh if set the transaction will be refreshed at given
251 * interval. Interval must be defined by including
252 * Expires-header. Ownership is transferred.
253 * @return SUBSCRIBE SIP transaction. Ownership is transferred.
254 * @leave KErrSIPInvalidDialogState if Dialog().State() is incorrect
255 * @capability NetworkServices
257 IMPORT_C CSIPClientTransaction*
258 SendSubscribeL(CSIPMessageElements* aElements=0,
259 CSIPRefresh* aRefresh=0);
262 * Updates the subscription. Note that update can be done when 2xx
263 * response is received to the initial SUBSCRIBE or to update.
264 * Client must not provide Event-header in the optional message headers.
265 * @pre aElements != 0
266 * @pre Dialog().Connection().State()==EActive
267 * Dialog().State()==CSIPDialog::EConfirmed
268 * @param aElements contains user SIP headers and content; the ownership
270 * @return SUBSCRIBE SIP client transaction; the ownership is transferred
271 * @leave KErrArgument if aElements == 0 or aElements contain
273 * @leave KErrSIPInvalidDialogState if Dialog().State() is incorrect
274 * @capability NetworkServices
276 IMPORT_C CSIPClientTransaction* UpdateL(CSIPMessageElements* aElements);
279 * Creates (un)SUBSCRIBE and sends it to the remote target.
280 * Possible associated refresh will be terminated as well.
281 * Client must not provide Event-header in the optional message headers.
282 * @pre Dialog().Connection().State()==EActive
283 * @pre Dialog().State()==CSIPDialog::EConfirmed
284 * @param aElements optional SIP message headers and body. Ownership is
286 * @return SUBSCRIBE SIP transaction. Ownership is transferred.
287 * @leave KErrSIPInvalidDialogState if Dialog().State() is incorrect
288 * @capability NetworkServices
290 IMPORT_C CSIPClientTransaction*
291 SendUnsubscribeL(CSIPMessageElements* aElements=0);
294 * Gets associated refresh in case the user has requested
295 * the refresh of the SIP subscription.
296 * Note that refreshed SUBSCRIBE dialog association cannot be
297 * terminated nor updated using the returned object.
298 * @return Associated refresh or 0 pointer if the user has not requested
299 * a refresh. Ownership is not transferred.
301 IMPORT_C const CSIPRefresh* SIPRefresh() const;
304 * Gets an event to which the subscription is done
307 IMPORT_C const CSIPEventHeader& Event() const;
309 public: // New functions, for internal use
314 CSIPRefresh* FindRefresh(TUint32 aRefreshId);
316 static CSIPSubscribeDialogAssoc* NewLC(CSIPConnection& aConnection,
318 CSIPEventHeader* aEvent,
319 CSIPFromHeader* aFrom,
321 CSIPContactHeader* aContact,
322 const MSIPRegistrationContext* aContext);
324 void ConnectionLost();
326 CSIPClientTransaction*
327 DoSendSubscribeL(CSIPMessageElements* aElements,
328 CSIPRefresh* aRefresh,
329 TBool aWithinDialog);
331 CSIPClientTransaction*
332 DoSendUnsubscribeL(CSIPMessageElements* aElements);
337 void DeletingRefresh(CSIPRefresh& aRefresh, TUint32 aRefreshId);
339 private: // Constructors
340 CSIPSubscribeDialogAssoc();
343 //If the subscription is refreshed, this is the used CSIPRefresh
344 //instance, otherwise this is NULL. CSIPSubscribeDialogAssoc owns this.
345 CSIPRefresh* iRefresh;
347 CSIPEventHeader* iEvent;
349 private: // For testing purposes
351 friend class CSIP_Test;
352 friend class CSIPSubscribeDialogAssoc_Test;