realtimenetprots/sipfw/SIP/Client/inc/sipclientconnection.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2007-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          : sipclientconnection.h
       
    16 * Part of       : SIPClient
       
    17 * Version       : SIP/6.0 
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25  @internalComponent
       
    26 */
       
    27 
       
    28 
       
    29 #ifndef CSIPCLIENTCONNECTION_H
       
    30 #define CSIPCLIENTCONNECTION_H
       
    31 
       
    32 #include <e32base.h>
       
    33 #include <stringpool.h>
       
    34 #include <uri8.h>
       
    35 #include <in_sock.h>
       
    36 #include "sipconnection.h"
       
    37 #include "_sipcodecdefs.h"
       
    38 
       
    39 class CSIPClient;
       
    40 class RSIPConnection;
       
    41 class CSIPITCSender;
       
    42 class MSIPClientConnectionObserver;
       
    43 class CSIPClientConnectionReceiver;
       
    44 class CSIPToHeader;
       
    45 class CSIPFromHeader;
       
    46 class CSIPRouteHeader;
       
    47 class CSIPCallIDHeader;
       
    48 class CSIPMessageElements;
       
    49 class CSIPRequestElements;
       
    50 class CSIPResponseElements;
       
    51 class CSIPContactHeader;
       
    52 
       
    53 /**
       
    54  * @brief Class for openening connection using particular IAP and 
       
    55  *        for managing SIP transactions/dialogs using given connection.
       
    56  * 
       
    57  *
       
    58  * Class provides functions for sending and receiving 
       
    59  * SIP requests and SIP responses.
       
    60  * This class also provides functions for creating and destroying SIP dialogs,
       
    61  * sending and receiving SIP requests and responses within SIP dialogs,
       
    62  * canceling the SIP requests.
       
    63  *
       
    64  * All SIP messages will be sent/received using connection (defined using IAP Id)
       
    65  * given by the user.
       
    66  *
       
    67  * If the preconditions or postconditions are not met the 
       
    68  * function will leave with KErrArgument error code.
       
    69  *
       
    70  */
       
    71 class CSIPClientConnection : public CBase
       
    72 	{
       
    73 public:
       
    74 
       
    75 	/**
       
    76 	 * Constructs an instance of CSIPClientConnection
       
    77      * The connection using IAP-Id is initialized during construction.
       
    78      * @param aClient a handle to SIP server session
       
    79      * @param aObserver an observer for receiving notifications
       
    80      * @param aIapId IAP Id that will be used for the connection.
       
    81 	 * @returns new instance, the ownership is transferred
       
    82 	 */
       
    83 
       
    84 	static CSIPClientConnection* NewL (CSIPClient& aClient,
       
    85 		                               MSIPClientConnectionObserver& aObserver,
       
    86 									   TUint32 aIapId);
       
    87 
       
    88 	/**
       
    89 	 * Constructs an instance of CSIPClientConnection and adds a pointer to it 
       
    90      * to the CleanupStack
       
    91      * The connection using IAP-Id is initialized during construction.
       
    92      * @param aClient a handle to SIP server session
       
    93      * @param aObserver an observer for receiving notifications
       
    94      * @param aIapId IAP Id that will be used for the connection.
       
    95 	 * @returns new instance, the ownership is transferred
       
    96 	 */
       
    97 
       
    98 	static CSIPClientConnection* NewLC (CSIPClient& aClient,
       
    99 		                                MSIPClientConnectionObserver& aObserver,
       
   100 										TUint32 aIapId);
       
   101 
       
   102 	/**
       
   103 	 * Destructor
       
   104 	 */
       
   105 
       
   106 	~CSIPClientConnection ();
       
   107 
       
   108 	/**
       
   109 	 * Gets the current state of the connection
       
   110      * @returns the connection state
       
   111 	 */
       
   112 
       
   113     CSIPConnection::TState State () const;
       
   114 
       
   115 	/**
       
   116 	 * Gets the IAP id of this connection
       
   117      * @returns the IAP id
       
   118 	 */
       
   119 
       
   120 	TUint32 IapId () const;
       
   121 	
       
   122     /**
       
   123 	 * Gets the local IP address used for this CSIPClientConnection
       
   124 	 * when sending SIP messages to the network.
       
   125 	 * @pre State() == EActive
       
   126 	 * @param aAddr local IP for this CSIPClientConnection.
       
   127      * @leave A system-wide error codes
       
   128      */ 	
       
   129      void GetLocalAddrL(TInetAddr& aAddr) const;	
       
   130 	
       
   131     /**
       
   132 	 * Sets a RSocket option used for all the sockets used for sending 
       
   133 	 * SIP requests and responses in this CSIPConnection.
       
   134 	 * @pre State() == EActive
       
   135 	 * @param aOptionName An integer constant which identifies an option.
       
   136      * @param aOptionLevel An integer constant which identifies 
       
   137      *        level of an option.
       
   138      * @param aOption Option value packaged in a descriptor.
       
   139      * @leave A system-wide error code
       
   140      */        
       
   141 	 void SetOptL(TUint aOptionName,
       
   142 	              TUint aOptionLevel,
       
   143 	              const TDesC8& aOption=KNullDesC8);
       
   144 	         
       
   145     /**
       
   146 	 * Sets a RSocket option used for all the sockets used for sending 
       
   147 	 * SIP requests and responses in this CSIPConnection.
       
   148 	 * @pre State() == EActive
       
   149 	 * @param aOptionName An integer constant which identifies an option.
       
   150      * @param aOptionLevel An integer constant which identifies 
       
   151      *        level of an option.
       
   152      * @param aOption Option value as an integer.
       
   153      * @leave A system-wide error codes
       
   154      */ 	                         
       
   155 	 void SetOptL(TUint aOptionName,
       
   156 	              TUint aOptionLevel,
       
   157 	              TInt aOption);  	
       
   158 	
       
   159 
       
   160 	/**
       
   161 	 * Sets the Outbound Proxy for a registration binding. 
       
   162 	 *
       
   163 	 * @param aRegistrationId the value of the registration-Id 
       
   164      *        that was returned in a response to an earlier REGISTER request.
       
   165      *        This value is used to identify the binding for which 
       
   166      *        the outbound proxy setting is to be set.
       
   167 	 * @param aOutboundProxy an outbound proxy.
       
   168 	 */
       
   169 	 
       
   170 	void SetOutboundProxyL (TUint32 aRegistrationId,
       
   171 	                        const CSIPRouteHeader& aOutboundProxy);
       
   172 
       
   173 	/**
       
   174 	 * Removes the outbound proxy which was used for the particular AOR.
       
   175 	 *
       
   176 	 * @param aRegistrationId the value of the registration-Id 
       
   177      *        that was returned in a response to an earlier REGISTER request. 
       
   178      *        This value is used to identify the binding for which 
       
   179      *        the outbound proxy setting is to be removed.
       
   180 	 * @returns KErrNone if a proxy was found and removed.
       
   181      *          KErrNotFound if a proxy was not found. 
       
   182      *          Otherwise a system wide error code.
       
   183 	 */
       
   184 
       
   185 	TInt RemoveOutboundProxy (TUint32 aRegistrationId);
       
   186 
       
   187 	/**
       
   188 	 * Gets the Outbound Proxy as set by any application for an AOR.
       
   189 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   190 	 * Applications should retrieve this value first and examine if outbound
       
   191 	 * proxy address, for the particular AOR, is suitable before sending SIP
       
   192 	 * requests to the sip stack. If not suitable, 
       
   193      * the application may add a Route-header to the SIP Request 
       
   194      * in order to override this setting for that particular request.
       
   195 	 *
       
   196 	 * @param aRegistrationId the value of the registration-Id 
       
   197      *        that was returned in a response to an earlier REGISTER request.
       
   198      *        This value is used to identify the binding for which 
       
   199      *        the outbound proxy setting is to be fetched.
       
   200 	 * @returns An outbound proxy object or 0 if not found,
       
   201 	 *          The ownership is transferred.
       
   202 	 */
       
   203 
       
   204 	CSIPRouteHeader* OutboundProxyL (TUint32 aRegistrationId);
       
   205 
       
   206 	/**
       
   207 	 * Gets the AOR for a given registration id.
       
   208 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   209 	 *
       
   210 	 * @param aRegistrationId the value of the registration-Id 
       
   211      *        that was returned in a response to an earlier REGISTER request.
       
   212      *        This value is used to identify the binding for which 
       
   213      *        the AOR is to be fetched.
       
   214 	 * @returns An AOR as a From-header object or 0 if not found,
       
   215 	 *          The ownership is transferred.
       
   216 	 */
       
   217 
       
   218 	CSIPFromHeader* AorL (TUint32 aRegistrationId);
       
   219 
       
   220 	/**
       
   221 	 * Creates SIP REGISTER request and sends it to the given destination.
       
   222 	 * Leaves on failure with a system wide or a SIP stack specific error code
       
   223 	 * This function call creates a registration binding.
       
   224 	 * The Registration-Id for this REGISTER is returned with a 
       
   225      * future 2xx response received for this REGISTER.
       
   226 	 * A 2xx response to this REGISTER creates a binding.
       
   227      * There MUST NOT be more than one Contact-header and 
       
   228      * it MUST NOT be set to STAR.
       
   229 	 * 
       
   230 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   231      * @pre aTo.SIPAddress().URI().HasUser()
       
   232      * @pre !aTo.HasTag()
       
   233      * @pre !aFrom.HasTag()
       
   234      * @pre aRemoteUri->IsSIPURI()
       
   235      *
       
   236 	 * @param aRequestId the returned request Id,
       
   237      *        to be used to match a response to this request.
       
   238 	 * @param aTo a To-header
       
   239 	 * @param aTo a From-header 
       
   240 	 * @param aElements contains optional SIP message headers and body.
       
   241      * @param aRemoteUri a remote-URI.
       
   242      *        The ownership is NOT transferred.
       
   243      * @param aOutboundProxy the outbound proxy address.
       
   244      *        The ownership is NOT transferred.
       
   245 	 * @param aRefresh refresh flag. Refreshing of this REGISTER is requested 
       
   246      *        from the SIP Stack by setting this flag to ETrue.
       
   247  	 * @param aSendWithExpires when set to EFalse REGISTER message is sent
       
   248 	 *        without expires value
       
   249 	 * @param aCacheOutboundProxyIP when set to ETrue outbound proxy IP
       
   250 	 *        of REGISTER message is cached in registration context
       
   251 	 */		
       
   252 
       
   253 	void SendRegisterL (TUint32& aRequestId,
       
   254 		                const CSIPToHeader& aTo,
       
   255 						const CSIPFromHeader& aFrom,
       
   256 						const CSIPMessageElements& aElements,
       
   257 						const CUri8* aRemoteUri=0,
       
   258 						const CSIPRouteHeader* aOutboundProxy=0,
       
   259 						TBool aRefresh=EFalse,
       
   260 						TBool aSendWithExpires=ETrue,
       
   261 						TBool aCacheOutboundProxyIP=EFalse);
       
   262 
       
   263 	/**
       
   264 	 * Creates SIP (update) REGISTER request and sends it to the given destination.
       
   265 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   266 	 * User of this function does not need to, but can, 
       
   267      * set a new expires values in the expires-param of the SIP REGISTER request.
       
   268 	 * This is done to update the refresh interval.
       
   269 	 * A 2xx response to this request updates a binding 
       
   270      * as well as the refresh interval.
       
   271 	 * 
       
   272 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   273 	 * @param aRegistrationId the value of the registration-Id 
       
   274      *        that was returned in a response, to an earlier REGISTER, 
       
   275      *        that created the binding. This value is used to 
       
   276 	 *		  identify the binding to be updated.
       
   277 	 * @param aNewRequestId the returned request Id, 
       
   278      *        to be used to match a response to this request.
       
   279 	 * @param aElements contains optional SIP message headers and body.
       
   280 	 */		
       
   281 
       
   282 	void UpdateRegistrationL (TUint32 aRegistrationId,
       
   283 		                      TUint32& aNewRequestId,
       
   284 							  const CSIPMessageElements* aElements=0);
       
   285 
       
   286 	/**
       
   287 	 * Creates SIP (un)REGISTER request and sends it to the given destination.
       
   288 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   289 	 * User must NOT set any expires values in the
       
   290 	 * SIP REGISTER request (aSIPMessageOptionalElements).
       
   291 	 * Any SIP response (2xx - 6xx) to this request removes a binding.
       
   292 	 * 
       
   293 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   294      * @pre "Contact-headers".Count() == 0
       
   295 	 * @param aRegistrationId the value of the registration-Id 
       
   296      *        that was returned in a response, to an earlier REGISTER,
       
   297      *        that created the binding. This value is used to 
       
   298 	 *        identify the binding to be removed.
       
   299 	 * @param aNewRequestId the returned request Id, 
       
   300      *        to be used to match a response to this request.
       
   301 	 * @param aElements contains optional SIP message headers and body.
       
   302 	 */
       
   303 
       
   304 	void UnregisterL (TUint32 aRegistrationId,
       
   305 		              TUint32& aNewRequestId,
       
   306 					  const CSIPMessageElements* aElements=0);
       
   307 
       
   308 	/**
       
   309 	 * Creates SIP REGISTER request and sends it to the given destination.
       
   310 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   311 	 * User must NOT set any expires values 
       
   312      * to the request (aMessageOptionalElements).
       
   313 	 * 
       
   314 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   315      * @pre !aElements.RemoteURI()->HasUser()
       
   316      * @pre aElements.ToHeader().SIPAddress().URI().HasUser()
       
   317 	 * @pre "Contact-headers".Count() == 0
       
   318 	 * @param aElements contains remote address and 
       
   319      *        optionally SIP message headers and body.
       
   320 	 * @param aRequestId the returned request Id, 
       
   321      *        to be used to match a response to this request.
       
   322 	 */		
       
   323 
       
   324 	void FetchRegistrationsL (const CSIPRequestElements& aElements,
       
   325 		                      TUint32& aRequestId);
       
   326 
       
   327 	/**
       
   328 	 * Creates SIP request and sends it to the given destination.
       
   329 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   330 	 * Function returns an error if a SIP request with a known method
       
   331 	 * as defined in preconditions is sent. 
       
   332      * This provokes the Non-invite state machine.
       
   333 	 * The registration Id is used to select the outbound proxy.
       
   334 	 * 
       
   335 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   336 	 * @pre aRequestElements.Method() != "REGISTER" | "OPTIONS" | "INVITE" 
       
   337      *      | "BYE" | "CANCEL" | "ACK" | "SUBSCRIBE" | "NOTIFY" | "REFER" 
       
   338      *      | "MESSAGE".
       
   339 	 * @param aElements contains local and remote addresses,
       
   340 	 *        optional SIP message headers and body.
       
   341 	 * @param aRequestId the returned request Id,
       
   342      *        to be used to match a response to this request.
       
   343 	 * @param aRegistrationId registration id for the sender's AOR
       
   344 	 * @param aRefresh refresh flag. Refreshing of the SIP request is requested
       
   345      *        from the SIP Stack by setting this flag to ETrue.
       
   346 	 */		
       
   347 
       
   348 	void SendRequestL (const CSIPRequestElements& aElements,
       
   349 		               TUint32& aRequestId,
       
   350 					   TUint32 aRegistrationId=0,
       
   351 					   TBool aRefresh=EFalse);
       
   352 
       
   353 	/**
       
   354 	 * Sends a SIP request and updates an existing refresh. 
       
   355      * The method and To- and From-headers
       
   356      * from the original request will be used.
       
   357 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   358 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   359      * @param aRefreshId the value of the refresh-Id that was returned 
       
   360      *        in a response to an earlier request that created the refresh.
       
   361 	 * @param aNewRequestId the returned request Id,
       
   362      *        to be used to match a response to this request.
       
   363 	 * @param aElements contains optional SIP message headers and body.
       
   364 	 */		
       
   365 
       
   366 	void SendRequestAndUpdateRefreshL (TUint32 aRefreshId,
       
   367 		                               TUint32& aNewRequestId,
       
   368 									   const CSIPMessageElements* aElements=0);
       
   369 
       
   370 
       
   371 	/**
       
   372 	 * Sends a SIP request and terminates the refresh after sending the request.
       
   373      * The method and To- and From-headers
       
   374      * from the original request will be used.
       
   375 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   376 	 * Any SIP response (2xx - 6xx) to this request terminates a refresh.
       
   377 	 *
       
   378 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   379      * @param aRefreshId the value of the refresh-Id that was returned 
       
   380      *        in a response to an earlier request that created the refresh.
       
   381 	 * @param aNewRequestId the returned request Id,
       
   382      *        to be used to match a response to this request.
       
   383 	 * @param aElements contains optional SIP message headers and body.
       
   384 	 */		
       
   385 
       
   386 	void SendRequestAndTerminateRefreshL (TUint32 aRefreshId,
       
   387 		                                  TUint32& aNewRequestId,
       
   388 										  const CSIPMessageElements* aElements=0);
       
   389 
       
   390 	/**
       
   391 	 * Creates SIP response and sends it to the given destination.
       
   392 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   393 	 * This response does not create a dialog. This function MUST
       
   394 	 * be used only if the request received had no Dialog-Id.
       
   395 	 *
       
   396 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   397 	 * @param aElements contains Status Code, optional Reason Phrase 
       
   398      *        and optional SIP message headers and body.
       
   399 	 * @param aRequestId the value of the request id as returned 
       
   400      *        by an earlier request. The value is used to identify the request
       
   401      *        to which this response is for.
       
   402 	 */		
       
   403 	
       
   404 	void SendResponseL (const CSIPResponseElements& aElements,
       
   405 		                TUint32 aRequestId);
       
   406 		                
       
   407 	/**
       
   408 	 * Creates SIP ACK request within a dialog and sends it 
       
   409      * to the given destination. 
       
   410      * Leaves on failure with a system wide or a SIP stack specific error code.
       
   411 	 *
       
   412 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   413      * @pre aElements.OptionalElements()->ContactHeaders().Count() == 0
       
   414 	 * @param aDialogId the value of the Dialog-Id that was returned 
       
   415      *        in a response to an earlier INVITE, that created the dialog.
       
   416 	 * @param aRequestId the value of the INVITE Request-Id.
       
   417 	 * @param aElements contains optional SIP message headers and body.
       
   418 	 */		
       
   419 
       
   420 	void SendAckL (TUint32 aDialogId,
       
   421 		           TUint32 aRequestId,
       
   422 				   const CSIPMessageElements* aElements=0);
       
   423 
       
   424 	/**
       
   425 	 * Creates SIP CANCEL request for an existing INVITE request and 
       
   426 	 * sends it to the given destination.
       
   427 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   428 	 * 
       
   429 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   430 	 * @param aInviteRequestId the id of the INVITE request to be cancelled.
       
   431 	 * @param aCancelRequestId the id to be created for the CANCEL request.
       
   432 	 */		
       
   433 
       
   434 	void SendCancelL (TUint32 aInviteRequestId,
       
   435 		              TUint32& aCancelRequestId);
       
   436 
       
   437 	/**
       
   438 	 * Creates SIP response and sends it to the given destination.
       
   439 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   440 	 * This response creates a dialog. 
       
   441 	 *
       
   442 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   443 	 * @param aElements contains Status Code, 
       
   444      *        optional Reason Phrase and optional SIP message headers and body.
       
   445 	 * @param aRequestId the value of the request id as returned by an 
       
   446      *        earlier received request. This value is used to identify 
       
   447      *        the request to which this response is for.
       
   448 	 * @param aDialogId a dialog id of the dialog that this response creates.
       
   449 	 * @param aRegistrationId registration id
       
   450 	 */		
       
   451 
       
   452 	void SendResponseAndCreateDialogL (const CSIPResponseElements& aElements,
       
   453 		                               TUint32 aRequestId,
       
   454 									   TUint32& aDialogId,
       
   455 									   TUint32 aRegistrationId);
       
   456 	 
       
   457 	/**
       
   458 	 * Creates SIP response to a request that is within a dialog
       
   459 	 * and sends it to the given destination.
       
   460      * Leaves on failure with a system wide or a SIP stack specific error code.
       
   461      * Contact-header MUST NOT be set if aTargetRefresh flag is EFalse.
       
   462 	 *
       
   463 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   464 	 * @param aElements contains Status Code, optional Reason Phrase
       
   465      *        and optional SIP message headers and body.
       
   466 	 * @param aRequestId the value of the request id as returned 
       
   467      *        by an earlier received request.
       
   468 	 *        This value identifies the request to which this response is for.
       
   469 	 * @param aDialogId the value of the dialog id as returned 
       
   470      *        by an earlier received response.
       
   471 	 *        This value identifies the dialog to which this response is for.
       
   472 	 * @param aTargetRefresh indicates if a received request 
       
   473      *        sent within a dialog was a target refresh request.
       
   474 	 */		
       
   475 
       
   476 	void SendResponseWithinDialogL (const CSIPResponseElements& aElements,
       
   477 		                            TUint32 aRequestId,
       
   478 									TUint32 aDialogId,
       
   479 									TBool aTargetRefresh=EFalse);
       
   480 
       
   481 	/**
       
   482 	 * Creates a SIP request and sends it to the given destination.
       
   483 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   484 	 * The Dialog-Id for this request is returned 
       
   485      * with a future 2xx response received for this request. 
       
   486      * This provokes the Non-invite state machine
       
   487 	 * The registration Id is used to select the outbound proxy.
       
   488      * There MUST NOT be more than one Contact-header and 
       
   489      * it MUST NOT be set to STAR.
       
   490 	 * 
       
   491 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   492      * @pre aMethod.Length() > 0
       
   493 	 * @pre aMethod != "REGISTER" | "OPTIONS" | "BYE" | "CANCEL" |
       
   494      *                 "ACK" | "NOTIFY" | "MESSAGE" | "PRACK" | "UPDATE"
       
   495      * @pre aRemoteUri->IsSIPURI()
       
   496      * @pre !aTo->HasTag()
       
   497      * @pre !aFrom.HasTag()
       
   498      *
       
   499 	 * @param aRequestId the returned request Id,
       
   500      *        to be used to match a response to this request.
       
   501 	 * @param aRefreshId if the request is refresh,
       
   502 	 *        contains on return the id of the created refresh.  
       
   503 	 * @param aDialogId the returned dialog Id of the establishing dialog     
       
   504      * @param aMethod the method
       
   505      * @param aRemoteUri a remote-URI.
       
   506 	 * @param aFrom a From-header. If not given, aRegistrationId must be given,
       
   507      *        so that the stack can fill in the From-header based on it.
       
   508      *        The ownership is NOT transferred.
       
   509 	 * @param aElements contains optional SIP message headers and body.
       
   510 	 * @param aTo a To-header. The ownership is NOT transferred.	 
       
   511 	 * @param aRegistrationId registration id for the sender's AOR
       
   512 	 * @param aRefresh refresh flag. Refreshing of this SIP request is requested 
       
   513      *        from the SIP Stack by setting this flag to ETrue.
       
   514 	 */		
       
   515 
       
   516 	void SendRequestAndCreateDialogL (TUint32& aRequestId,
       
   517 	                                  TUint32& aRefreshId,
       
   518 	                                  TUint32& aDialogId,
       
   519 		                              RStringF aMethod,
       
   520 		                              const CUri8& aRemoteUri,
       
   521 									  const CSIPFromHeader* aFrom,
       
   522 									  const CSIPMessageElements* aElements=0,
       
   523 									  const CSIPToHeader* aTo=0,
       
   524 									  TUint32 aRegistrationId=0,
       
   525 									  TBool aRefresh=EFalse);
       
   526 	/**
       
   527 	 * Creates a SIP request within a dialog and sends it to the given destination.
       
   528 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   529 	 * Contact header SHOULD NOT be created unless user intends to redirect 
       
   530      * the future requests within this dialog to a different remote target. 
       
   531      * Contact-header MUST NOT be set if aTargetRefresh flag is EFalse.
       
   532 	 * This provokes the Non-invite state machine
       
   533 	 *
       
   534 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   535      * @pre aMethod.Length() > 0
       
   536 	 * @pre aMethod != "REGISTER" | "CANCEL" | "ACK"
       
   537 	 * @param aDialogId the value of the Dialog-Id that was returned in 
       
   538      *        a response to an earlier request that created the dialog.
       
   539 	 * @param aNewRequestId the returned request Id,
       
   540      *        to be used to match a response to this request.
       
   541 	 * @param aRefreshId if the request is refresh,
       
   542 	 *        contains on return the id of the created refresh.
       
   543      * @param aMethod the method of the request
       
   544 	 * @param aElements contains optional SIP message headers and body.
       
   545 	 * @param aTargetRefresh indicates if an unknown request 
       
   546      *        is a target refresh request.
       
   547 	 * @param aRefresh refresh flag. Refreshing of this SIP request 
       
   548      *        is requested from the SIP Stack by setting this flag to ETrue.
       
   549 	 */		
       
   550 
       
   551 	void SendRequestWithinDialogL (TUint32 aDialogId,
       
   552 		                           TUint32& aNewRequestId,
       
   553 		                           TUint32& aRefreshId,
       
   554 								   RStringF aMethod,
       
   555 								   const CSIPMessageElements* aElements=0,
       
   556 								   TBool aTargetRefresh=EFalse,
       
   557 								   TBool aRefresh=EFalse);
       
   558 
       
   559 	/**
       
   560 	 * Creates a SIP request within a dialog and sends it to the given destination.
       
   561 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   562      * Contact-header MUST NOT be set.
       
   563      * Üpdates an existing refresh within a dialog.
       
   564      * This function can also be used to terminate an existing refresh
       
   565      * by setting the Expires-header's value to zero.
       
   566      * Expires header is mandatory.
       
   567 	 *
       
   568 	 * @pre CSIPConnection::State() == CSIPConnection::EActive.
       
   569      * @pre aMethod.Length() > 0
       
   570 	 * @param aDialogId the value of the Dialog-Id that was returned in 
       
   571      *        a response to an earlier request that created the dialog.
       
   572 	 * @param aRefreshId the value of the Refresh-Id that was returned
       
   573      *        in a response to an earlier request that created the refresh.
       
   574 	 * @param aNewRequestId the returned request Id,
       
   575      *        to be used to match a response to this request.
       
   576 	 * @param aElements contains optional SIP message headers and body.
       
   577 	 */		
       
   578 
       
   579 	void SendRequestWithinDialogL (TUint32 aDialogId,
       
   580 		                           TUint32 aRefreshId,
       
   581 								   TUint32& aNewRequestId,
       
   582 								   const CSIPMessageElements* aElements);
       
   583 
       
   584 	/**
       
   585 	 * Gets the Call-ID for a given dialog id.
       
   586 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   587 	 *
       
   588 	 * @param aDialogId a dialog id
       
   589 	 * @returns A Call-ID header if the dialog was found. 
       
   590 	 *          The ownership is transferred.
       
   591 	 */
       
   592 
       
   593 	CSIPCallIDHeader* CallIDL (TUint32 aDialogId);
       
   594 	
       
   595 	/**
       
   596 	 * Gets the local tag for a given dialog id.
       
   597 	 * Leaves on failure with a system wide or a SIP stack specific error code.
       
   598 	 *
       
   599 	 * @param aDialogId a dialog id
       
   600 	 * @returns Local tag if the dialog was found. 
       
   601 	 *          The ownership is transferred (the caller must call Close).
       
   602 	 */
       
   603 
       
   604 	RStringF LocalTagL (TUint32 aDialogId);	
       
   605 
       
   606 	/**
       
   607 	 * Gets the Contact-header that has been registered
       
   608 	 * with the given registration id.
       
   609 	 *
       
   610 	 * @param aRegistrationId the value of the registration-Id 
       
   611      *        that was returned in a response to an earlier REGISTER request.
       
   612      *        This value is used to identify the binding for which 
       
   613      *        the Contact-header is to be fetched.
       
   614 	 * @returns the registered Contact-header
       
   615 	 */
       
   616     CSIPContactHeader* ContactL (TUint32 aRegistrationId);
       
   617 
       
   618 	/**
       
   619 	 * Terminates a dialog. This function can be used to terminate a
       
   620 	 * dialog abnormally or when the dialog does not have any more
       
   621 	 * associations (E.g. After receiving a final response to a BYE request).
       
   622 	 *
       
   623 	 * @param aDialogId dialog id for the dialog to be terminated.
       
   624 	 * @returns system wide or SIP stack specific error code.
       
   625 	 */
       
   626 	TInt TerminateDialog (TUint32 aDialogId);
       
   627 
       
   628 	/**
       
   629 	 * Terminates a refresh abnormally.
       
   630 	 *
       
   631 	 * @param aRefreshId refresh id of the refresh to be terminated.
       
   632 	 * @returns system wide or SIP stack specific error code.
       
   633 	 */
       
   634 	TInt TerminateRefresh (TUint32 aRefreshId);
       
   635 
       
   636 
       
   637     void SetRefreshIntervalL (TUint32 aRefreshId, TUint aInterval);
       
   638 
       
   639 
       
   640     TUint RefreshIntervalL (TUint32 aRefreshId);
       
   641 
       
   642 
       
   643 	TInt TerminateDialogRefresh (TUint32 aDialogId,
       
   644                                  TUint32 aRefreshId);
       
   645 
       
   646     TInt TerminateRegistration (TUint32 aId);
       
   647 
       
   648     TInt ResetDialogState (TUint32 aDialogId);
       
   649 
       
   650 	/**
       
   651 	 * Clear the link from CSIPClientConnection to CSIPClient.
       
   652 	 */
       
   653 	void DetachClient();
       
   654 
       
   655 	/**
       
   656 	 * Refreshes the connection
       
   657 	 */
       
   658 	void RefreshConnection() const;
       
   659 	
       
   660 	/**
       
   661 	 * Returns the connection error code
       
   662 	 */ 
       
   663 	TInt ConnectionErrorL() const;
       
   664 	
       
   665 private:
       
   666 
       
   667 	CSIPClientConnection (CSIPClient& aClient,
       
   668                           MSIPClientConnectionObserver& aObserver,
       
   669                           TUint32 aIapId);
       
   670 
       
   671 	void ConstructL ();
       
   672 
       
   673     void CheckDialogCreationRequestL (const CSIPToHeader* aTo,
       
   674                                       const CSIPFromHeader* aFrom,
       
   675                                       const CSIPMessageElements* aElements,
       
   676                                       TUint32 aRegistrationId,
       
   677                                       TBool aRefresh=EFalse);
       
   678 
       
   679     void CheckContactExpiresL (const CSIPMessageElements& aElements) const;
       
   680 	void CheckContactL (const CSIPMessageElements* aElements) const;
       
   681     void CheckContactL (const CSIPMessageElements& aElements) const;
       
   682     void CheckExpiresHeaderL (const CSIPMessageElements* aElements,
       
   683                               TBool aZeroAllowed=EFalse) const;
       
   684     void CheckExpiresHeaderL (const CSIPMessageElements& aElements,
       
   685                               TBool aZeroAllowed=EFalse) const;
       
   686 
       
   687                               
       
   688 private: // Data                              
       
   689 
       
   690     CSIPClient& iClient;
       
   691     MSIPClientConnectionObserver& iObserver;
       
   692     TUint32 iIapId;
       
   693 	RSIPConnection* iConnection;
       
   694     CSIPITCSender* iSender;
       
   695 	CSIPClientConnectionReceiver* iReceiver;
       
   696     TBool iAdded;
       
   697     RStringF iTag;
       
   698     RStringF iContactHeaderName;
       
   699     RStringF iExpiresHeaderName;
       
   700 
       
   701 private: // For testing purposes
       
   702 
       
   703     UNIT_TEST(CSIPClientConnectionTest)
       
   704     UNIT_TEST(CSIPClientTest)
       
   705 	};
       
   706 
       
   707 #endif // CSIPCLIENTCONNECTION_H
       
   708 
       
   709 // End of File