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 : sipconnection.h
16 * Part of : SIP Client
17 * Interface : SDK API, SIP API
24 #ifndef CSIPCONNECTION_H
25 #define CSIPCONNECTION_H
31 // FORWARD DECLARATIONS
33 class MSIPConnectionObserver;
34 class CSIPClientTransaction;
35 class MSIPRegistrationContext;
37 class CSIPRequestElements;
38 class CSIPConnectionImplementation;
48 * Class for monitoring connection's state and sending SIP requests outside
49 * the dialog associations. Class must not be used
50 * - for sending requests to which received non-failure response creates a dialog
51 * - for sending requests that must be sent within SIP dialog
53 * Note that the user can have only one instance of the class per same IAP-id.
55 class CSIPConnection : public CBase
58 /** Connection states */
61 /** Connection initializing */
63 /** Connection active */
65 /** Connection suspended */
67 /** Connection is inactive */
69 /** Connection is permanently unavailable */
73 public: // Constructors and destructor
76 * Two-phased constructor.
77 * @param aSip a handle to the SIP server
78 * @param aIapId IAP-id
79 * @param aObserver a observer for receiving asynchonous events on this
81 * @return New object, ownership is transferred
82 * @capability NetworkServices
84 IMPORT_C static CSIPConnection*
87 MSIPConnectionObserver& aObserver);
90 * Two-phased constructor.
91 * Constructs an object and adds the pointer to the cleanup stack;
92 * @param aSip a handle to the SIP server
93 * @param aIapId IAP-id
94 * @param aObserver a observer for receiving asynchonous events on this
96 * @return New object, ownership is transferred
97 * @capability NetworkServices
99 IMPORT_C static CSIPConnection*
102 MSIPConnectionObserver& aObserver);
106 * @capability NetworkServices
108 IMPORT_C ~CSIPConnection();
110 public: // New functions
113 * Gets current state of the connection
114 * @return current state of the connection
116 IMPORT_C TState State() const;
119 * Creates SIP request and sends it to the given destination.
120 * The function must not be used with SIP requests that creates
121 * SIP dialog associations or must be sent within SIP dialog
123 * This provokes the Non-invite state machine.
124 * This function must be used if the user has created the
125 * registration binding.
126 * @pre State() == EActive.
127 * @pre aContext.IsContextActive() == ETrue
128 * @param aElements contains local and remote addresses,
129 * optional SIP message headers and body.
130 * The ownership is transferred.
131 * @param aContext defines outbound proxy to be used. If the user
132 * does not provide from-address it will be constucted using
133 * user's AOR used during the registration.
134 * @return SIP client transaction, ownership is transferred
135 * @leave KErrArgument if aElements == 0
136 * @leave KErrSIPInvalidRegistrationState if aContext.IsContextActive()
138 * @capability NetworkServices
140 IMPORT_C CSIPClientTransaction*
141 SendRequestL(CSIPRequestElements* aElements,
142 const MSIPRegistrationContext& aContext);
145 * Creates SIP request and sends it to the given destination.
146 * The function must not be used with SIP requests that creates
147 * SIP dialog associations or must be sent within SIP dialog
149 * This provokes the Non-invite state machine.
150 * This function must be used if the user has created the
151 * registration binding.
152 * @pre State() == EActive.
153 * @pre aContext.IsContextActive() == ETrue
154 * @param aElements contains local and remote addresses,
155 * optional SIP message headers and body.
156 * The ownership is transferred.
157 * @param aContext defines outbound proxy to be used. If the user
158 * does not provide from-address it will
159 * be constucted using user's AOR used during the registration.
160 * @param aRefresh defines the refresh interval for this transaction.
161 * @return SIP client transaction, ownership is transferred
162 * @leave KErrArgument if aElements == 0
163 * @leave KErrSIPInvalidRegistrationState if aContext.IsContextActive()
165 * @capability NetworkServices
167 IMPORT_C CSIPClientTransaction*
168 SendRequestL(CSIPRequestElements* aElements,
169 const MSIPRegistrationContext& aContext,
170 CSIPRefresh& aRefresh);
173 * Creates SIP request and sends it to the given destination.
174 * The function must not be used with SIP requests that creates SIP
175 * dialog associations or must be sent within SIP dialog association.
176 * This invokes the Non-invite state machine.
177 * @pre State() == EActive.
178 * @pre aElements.FromHeader() != 0
179 * @param aElements contains local and remote addresses,
180 * optional SIP message headers and body.
181 * The ownership is transferred.
182 * @return SIP client transaction, ownership is transferred
183 * @leave KErrArgument if aElements == 0 or if From-header is not
184 * present in aElements
185 * @capability NetworkServices
187 IMPORT_C CSIPClientTransaction*
188 SendRequestL(CSIPRequestElements* aElements);
191 * Creates SIP request and sends it to the given destination.
192 * The function must not be used with SIP requests that creates SIP
193 * dialog associations or must be sent within SIP dialog association.
194 * This invokes the Non-invite state machine.
195 * @pre State() == EActive.
196 * @pre aElements.FromHeader() != 0
197 * @param aElements contains local and remote addresses,
198 * optional SIP message headers and body.
199 * The ownership is transferred.
200 * @param aRefresh indicates that transaction will be refreshed
201 * @return SIP client transaction, ownership is transferred
202 * @leave KErrArgument if aElements == 0 or if From-header is not
203 * present in aElements
204 * @capability NetworkServices
206 IMPORT_C CSIPClientTransaction*
207 SendRequestL(CSIPRequestElements* aElements,
208 CSIPRefresh& aRefresh);
211 * Creates SIP REGISTER request and sends it to the given destination.
212 * User must no define any Contact or Expires-headers
213 * in the provided elements.
214 * @pre State() == EActive
215 * @pre aElements != 0
216 * @pre aElements->Method().DesC().Length()==0
217 * @param aElements contains local and remote addresses, optional SIP
218 * message headers and body. User must not set any expires values
219 * to aElements. The ownership is transferred.
220 * @return SIP REGISTER client transaction, ownership is transferred
221 * @leave KErrArgument if aElements == 0 or if the request method has
222 * been defined in aElements
223 * @capability NetworkServices
225 IMPORT_C CSIPClientTransaction*
226 FetchRegistrationsL(CSIPRequestElements* aElements);
229 * Gets Iap-id used for this connection
232 IMPORT_C TUint32 IapId() const;
235 * Gets SIP server handle
236 * @return handle to SIP server, or 0-pointer if SIP server does not
239 IMPORT_C CSIP* SIP();
242 * Gets SIP server handle
243 * @return handle to SIP server, or 0-pointer if SIP server does not
246 IMPORT_C const CSIP* SIP() const;
249 * Sets a RSocket option used for all the sockets used for sending
250 * SIP requests and responses in this CSIPConnection.
251 * @pre State() == EActive
252 * @param aOptionName An integer constant which identifies an option.
253 * @param aOptionLevel An integer constant which identifies
254 * level of an option.
255 * @param aOption Option value packaged in a descriptor.
256 * @leave A system-wide error code
257 * @capability NetworkControl
258 * @capability NetworkServices
259 * @capability Location
260 * @capability ReadDeviceData
261 * @capability WriteDeviceData
263 IMPORT_C void SetOptL(TUint aOptionName,
265 const TDesC8& aOption=KNullDesC8);
268 * Sets a RSocket option used for all the sockets used for sending
269 * SIP requests and responses in this CSIPConnection.
270 * @pre State() == EActive
271 * @param aOptionName An integer constant which identifies an option.
272 * @param aOptionLevel An integer constant which identifies
273 * level of an option.
274 * @param aOption Option value as an integer.
275 * @leave A system-wide error codes
276 * @capability NetworkControl
277 * @capability NetworkServices
278 * @capability Location
279 * @capability ReadDeviceData
280 * @capability WriteDeviceData
282 IMPORT_C void SetOptL(TUint aOptionName,
287 * Gets the local IP address of this CSIPConnection
288 * that is used by the SIP implementation.
289 * The user should re-new the call whenever the connection state changes
290 * to the CSIPConnection::EActive in order to verify the correctness of
291 * the previously retrieved local IP address. The local IP address might
292 * be different as a result of the connection state change.
293 * @pre State() == CSIPConnection::EActive
294 * @param aAddr on return filled with local IP address
295 * @leave a system-wide error code
297 IMPORT_C void GetLocalAddrL(TInetAddr& aAddr) const;
300 * Refreshes the connection.
301 * This will retrieve the Bearer Monitor Instance if any, is available for this CSIPConnection and issue a Connection Refresh Request to it.
302 * The state of the Connection can be retrieved from State() to check if there is any change after Refreshing the connection.
303 * @capability NetworkServices.
306 IMPORT_C void RefreshConnection() const;
309 * Gets the connection error code
310 * @param aError will be filled with the error code
311 * @leave a system-wide error code
312 * @capability NetworkServices.
314 IMPORT_C void GetConnectionErrorL(TInt &aError) const;
316 public: // New functions, for internal use
319 * Returns the implementation instance.
321 * @return CSIPConnectionImplementation
323 CSIPConnectionImplementation& Implementation();
325 private: // Constructors
329 void ConstructL(CSIP& aSIP,
331 MSIPConnectionObserver& aObserver);
335 CSIPConnectionImplementation* iImplementation;
337 private: // For testing purposes
339 friend class CSIP_Test;
340 friend class CSIPConnection_Test;
341 friend class CSIPSubscribeDialogAssoc_Test;
342 friend class CSIPInviteDialogAssoc_Test;
343 friend class CSIPReferDialogAssoc_Test;
344 friend class CSIPNotifyDialogAssoc_Test;
345 friend class CSIPDialogTrying_Test;
346 friend class CSIPRegistrationBinding_Test;
348 void __DbgTestInvariant() const;