mmsharing/mmshavailability/tsrc/ut_availability/Stubs/inc/sipconnection.h
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     1 /*
       
     2 * Copyright (c) 2003 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 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CSIPCONNECTION_H
       
    20 #define CSIPCONNECTION_H
       
    21 
       
    22 #include "musunittesting.h"
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <in_sock.h>
       
    26 
       
    27 // FORWARD DECLARATIONS
       
    28 class CSIP;
       
    29 class MSIPConnectionObserver;
       
    30 class CSIPTransactionBase;
       
    31 class CSIPClientTransaction;
       
    32 class CSIPServerTransaction;
       
    33 class MSIPRegistrationContext;
       
    34 class CSIPRegistrationBinding;
       
    35 class CRegistrationState;
       
    36 class CSIPDialog;
       
    37 class CDialogState;
       
    38 class CSIPRefresh;
       
    39 class CSIPMessageElements;
       
    40 class CSIPRequestElements;
       
    41 class CSIPResponseElements;
       
    42 class CSIPClientConnectionObserver;
       
    43 class CConnectionCallback;
       
    44 class CSIPClientConnection;
       
    45 
       
    46 
       
    47 //CONSTANTS
       
    48 /** SIP minimum value for the expiration in seconds*/
       
    49 //const TUint KSIPMinExpirationValue=60;
       
    50 
       
    51 
       
    52 // CLASS DECLARATION
       
    53 
       
    54 /**
       
    55 *  Class for monitoring connection's state and sending SIP requests outside
       
    56 *  the dialog associations.Class must not be used
       
    57 *  -for sending requests to which received non-failure response creates a dialog
       
    58 *  -for sending requests that must be sent within SIP dialog
       
    59 * Note that the user can have only one instance of the class per same IAP-id
       
    60 */
       
    61 class CSIPConnection :
       
    62     public CBase
       
    63 	{
       
    64     public:
       
    65     
       
    66         /** Connection states */
       
    67         enum TState 
       
    68             {
       
    69             /** Connection initializing */
       
    70 			EInit=1,
       
    71 			/** Connection active */
       
    72 			EActive,
       
    73 			/** Connection suspended */
       
    74 			ESuspended,
       
    75 			/** Connection is inactive */
       
    76 			EInactive,
       
    77 			/** Connection is permanently unavailable */
       
    78 			EUnavailable
       
    79             };
       
    80 
       
    81     public:  // Constructors and destructor
       
    82 
       
    83 	    /**
       
    84         * Two-phased constructor.
       
    85 		* @param aSip a handle to the SIP server
       
    86 		* @param aIapId IAP-id
       
    87 		* @param aObserver a observer for receiving asynchonous events on this
       
    88         *   connection
       
    89         * @return New object, ownership is transferred
       
    90         */
       
    91 
       
    92 		IMPORT_C static CSIPConnection*
       
    93             NewL(CSIP& aSIP,
       
    94 				 TUint32 aIapId,
       
    95 				 MSIPConnectionObserver& aObserver);
       
    96 
       
    97 
       
    98 	    /**
       
    99         * Two-phased constructor.
       
   100 		* Constructs an object and adds the pointer to the cleanup stack;
       
   101 		* @param aSip a handle to the SIP server
       
   102 		* @param aIapId IAP-id
       
   103 		* @param aObserver a observer for receiving asynchonous events on this
       
   104         *   connection
       
   105         * @return New object, ownership is transferred
       
   106         */
       
   107 
       
   108 		IMPORT_C static CSIPConnection*
       
   109             NewLC(CSIP& aSIP,
       
   110 				  TUint32 aIapId,
       
   111 				  MSIPConnectionObserver& aObserver);
       
   112 
       
   113 
       
   114 		/**
       
   115 		* Destructor
       
   116 		*/
       
   117 
       
   118 		IMPORT_C ~CSIPConnection();
       
   119 
       
   120     public: // New functions
       
   121 
       
   122         /**
       
   123 		* Gets current state of the connection        
       
   124         * @return current state of the connection
       
   125         */
       
   126 
       
   127 		IMPORT_C TState State() const;
       
   128 
       
   129         /**
       
   130 		* Creates SIP request and sends it to the given destination.
       
   131 		* The function must not be used with SIP requests that creates
       
   132 		* SIP dialog associations or must be sent within SIP dialog
       
   133 		* association.
       
   134 		* This provokes the Non-invite state machine.
       
   135 		* This function must be used if the user has created the
       
   136 		* registration binding.
       
   137 		* @pre State() == EActive.
       
   138 		* @pre aContext.IsContextActive()==ETrue
       
   139 		* @param aElements contains local and remote addresses,
       
   140 		*		 optional SIP message headers and body.
       
   141 		*        The ownership is transferred.
       
   142 		* @param aContext defines outbound proxy to be used. If the user
       
   143 		*        does not provide from-address it will be constucted using
       
   144 		*        user's AOR used during the registration.
       
   145         * @return SIP client transaction, ownership is transferred
       
   146         */
       
   147 
       
   148 		IMPORT_C CSIPClientTransaction*
       
   149             SendRequestL(CSIPRequestElements* aElements,
       
   150                          const MSIPRegistrationContext& aContext);
       
   151 
       
   152 
       
   153         /**
       
   154 		* Creates SIP request and sends it to the given destination.
       
   155 		* The function must not be used with SIP request that creates
       
   156 		* SIP dialog associations or must be sent within SIP diallog
       
   157 		* association.
       
   158 		* This provokes the Non-invite state machine.
       
   159 		* This function must be used if the user has created the
       
   160 		* registration binding.
       
   161 		* @pre State() == EActive.
       
   162 		* @pre aContext.IsContextActive()==ETrue
       
   163 		* @param aElements contains local and remote addresses,
       
   164 		*		 optional SIP message headers and body.
       
   165 		*        The ownership is transferred.
       
   166 		* @param aContext defines outbound proxy to be used. If the user
       
   167 		*        does not provide from-address it will 
       
   168 		*        be constucted using user's AOR used during the registration.
       
   169 		* @param aRefresh defines the refresh interval for this transaction.
       
   170         * @return SIP client transaction, ownership is transferred
       
   171         */
       
   172 
       
   173 		IMPORT_C CSIPClientTransaction*
       
   174             SendRequestL(CSIPRequestElements* aElements,                                        
       
   175                          const MSIPRegistrationContext& aContext,
       
   176 						 CSIPRefresh& aRefresh); 
       
   177 
       
   178 
       
   179         /**
       
   180 		* Creates SIP request and sends it to the given destination.
       
   181 		* The function must not be used with SIP request that creates SIP
       
   182 		* diallog associations or must be sent within SIP dialog association.
       
   183 		* This invokes the Non-invite state machine.
       
   184 		* @pre State() == EActive.
       
   185 		* @pre aElements.FromHeader() != 0
       
   186 		* @param aElements contains local and remote addresses,
       
   187 		*		 optional SIP message headers and body.
       
   188 		*        The ownership is transferred.
       
   189         * @return SIP client transaction, ownership is transferred
       
   190         */
       
   191 
       
   192 		IMPORT_C CSIPClientTransaction*
       
   193             SendRequestL(CSIPRequestElements* aElements);
       
   194         
       
   195 
       
   196         /**
       
   197 		* Creates SIP request and sends it to the given destination.
       
   198 		* The function must not be used with SIP request that creates SIP
       
   199 		* dialog associations or must be sent within SIP dialog association.
       
   200 		* This invokes the Non-invite state machine.
       
   201 		* @pre State() == EActive.
       
   202 		* @pre aElements.FromHeader() != 0
       
   203 		* @param aElements contains local and remote addresses,
       
   204 		*		 optional SIP message headers and body.
       
   205 		*        The ownership is transferred.
       
   206 		* @param aRefresh indicates that transaction will be refreshed
       
   207         * @return SIP client transaction, ownership is transferred
       
   208         */
       
   209 
       
   210 		IMPORT_C CSIPClientTransaction*
       
   211             SendRequestL(CSIPRequestElements* aElements,
       
   212 						 CSIPRefresh& aRefresh);
       
   213 
       
   214 
       
   215         /**
       
   216 		* Creates SIP REGISTER request and sends it to the given destination.
       
   217 		* User must no define any Contact or Expires-headers
       
   218 		* in the provided elements.
       
   219 		* @pre State() == EActive
       
   220         * @pre aElements != 0
       
   221 		* @pre aElements->Method().DesC().Length()==0
       
   222 		* @param aElements contains local and remote addresses, optional SIP
       
   223         *        message headers and body. User must not set any expires values
       
   224         *        to aElements. The ownership is transferred.
       
   225         * @return SIP REGISTER client transaction, ownership is transferred
       
   226         */
       
   227 
       
   228 		IMPORT_C CSIPClientTransaction*
       
   229             FetchRegistrationsL(CSIPRequestElements* aElements);
       
   230             
       
   231         // Not in real SIP API:
       
   232         IMPORT_C void SetState(TState aState);    
       
   233 
       
   234 		//TODO:SHOULD THIS NEW FUNCTION BE INCLUDED INTO STUB???
       
   235 		/**
       
   236 		* Gets Iap-id used for this connection
       
   237 		* @return Iap-id
       
   238 		*/
       
   239 		
       
   240 		IMPORT_C TUint32 IapId() const;
       
   241 
       
   242 	        /**
       
   243         * Gets the local IP address of this CSIPConnection 
       
   244         * that is used by the SIP implementation.
       
   245         * The user should re-new the call whenever the connection state changes
       
   246         * to the CSIPConnection::EActive in order to verify the correctness of
       
   247         * the previously retrieved local IP address. The local IP address might
       
   248         * be different as a result of the connection state change.
       
   249         * @pre State() == CSIPConnection::EActive
       
   250         * @param aAddr on return filled with local IP address
       
   251         * @leave a system-wide error code
       
   252         */ 	                         
       
   253 	    IMPORT_C void GetLocalAddrL(TInetAddr& aAddr) const;
       
   254 		
       
   255 		
       
   256 		/**
       
   257         * Gets SIP server handle
       
   258         * @return handle to SIP server, or 0-pointer if SIP server does not
       
   259         *	exist any more
       
   260         */
       
   261         IMPORT_C CSIP* SIP();
       
   262   
       
   263 		/**
       
   264         * Gets SIP server handle
       
   265         * @return handle to SIP server, or 0-pointer if SIP server does not
       
   266         *	exist any more
       
   267         */
       
   268         
       
   269         IMPORT_C const CSIP* SIP() const;
       
   270 		//TODO:ENDS
       
   271 		
       
   272         /**
       
   273 		* Incoming request outside dialog has been received.
       
   274 		*
       
   275 		* @param aTransaction Server transaction. Ownership is transferred.        
       
   276         */
       
   277 
       
   278         void IncomingRequestL(CSIPServerTransaction* aTransaction) const;
       
   279 
       
   280         
       
   281         /**
       
   282 		* Incoming request within dialog has been received.
       
   283 		*
       
   284 		* @param aTransaction Server transaction. Ownership is transferred.
       
   285         * @param aDialogId Identifies the dialog to which the transaction
       
   286         *   belongs to.
       
   287         */
       
   288 
       
   289         void IncomingDialogRequestL(CSIPServerTransaction* aTransaction,
       
   290                               		TUint32 aDialogId);
       
   291 
       
   292         void IncomingResponseL(CSIPResponseElements* aElements,
       
   293                                TUint32 aRequestId) const;
       
   294     
       
   295         void IncomingRegistrationResponseL(CSIPResponseElements* aElements,
       
   296 		                       			   TUint32 aRequestId,
       
   297 					           			   TUint32 aRegistrationId) const;
       
   298 
       
   299         void IncomingRefreshResponseL(CSIPResponseElements* aElements,
       
   300 		                       		  TUint32 aRequestId,
       
   301 							   		  TUint32 aRefreshId);
       
   302 
       
   303 
       
   304         void ErrorOccured(TInt aError, TUint32 aRequestId) const;
       
   305 
       
   306         void RefreshErrorOccured(TInt aError, TUint32 aRefreshId) const;
       
   307 
       
   308 	    void RegistrationErrorOccured(TInt aError,
       
   309                           			  TUint32 aRegistrationId,
       
   310                           			  TUint32 aRequestId) const;
       
   311 
       
   312 		void DialogErrorOccured(TInt aError,
       
   313                           		TUint32 aDialogId,
       
   314                           		TUint32 aRequestId) const;
       
   315 
       
   316         void DialogErrorOccured(TInt aError,
       
   317                           		TUint32 aDialogId,
       
   318                           		TUint32 aRefreshId,
       
   319                           		TUint32 aRequestId) const;
       
   320 
       
   321         void ConnectionStateChanged(CSIPConnection::TState aState);
       
   322 
       
   323         void InviteCompleted(TUint32 aRequestId) const;
       
   324 
       
   325 
       
   326 		/**
       
   327         * Searches for a transaction with the matching aRequestId.
       
   328 		* @param aRequestId RequestId associated with the transaction
       
   329 		* @return Found transaction or NULL if not found. Ownership is not
       
   330         *   transferred.
       
   331         */
       
   332         
       
   333         CSIPTransactionBase* FindTransaction(TUint32 aRequestId) const;
       
   334    
       
   335    
       
   336         TInt AddRegistration(CSIPRegistrationBinding* aRegistration);
       
   337         void RemoveRegistration(const CSIPRegistrationBinding* aRegistration);
       
   338         
       
   339 
       
   340       /**
       
   341         * Searches for a registration binding, using aRegistrationId and
       
   342         * aRequestId as keys. Registration might not yet have received
       
   343         * RegistrationId from SIP client, so the aRequestId may be needed to
       
   344         * locate the registration binding.
       
   345         * @param aRegistrationId RegistrationId of the registration binding
       
   346 		* @param aRequestId RequestId of a transaction associated with the
       
   347         *   registration
       
   348 		* @return Found registration binding or NULL if not found.
       
   349 		*	Ownership is not transferred.
       
   350         */
       
   351         
       
   352         CSIPRegistrationBinding* FindRegistration(TUint32 aRegistrationId,
       
   353                              			   		  TUint32 aRequestId) const;
       
   354 
       
   355 
       
   356         TInt AddDialog(CSIPDialog* aDialog);
       
   357         void RemoveDialog(const CSIPDialog* aDialog);
       
   358 
       
   359 
       
   360         /**
       
   361         * Searches for a dialog, using aRequestId as a key.
       
   362         * @param aRequestId RequestId of a transaction associated with the
       
   363         *   dialog
       
   364 		* @return Found dialog or NULL if not found. Ownership is not
       
   365         *   transferred.
       
   366         */
       
   367 
       
   368         CSIPDialog* FindDialogByRequestId(TUint32 aRequestId) const;
       
   369 
       
   370 
       
   371         /**
       
   372 		* Informs CSIPConnection that the associated CSIP instance has been
       
   373         * deleted. After this the CSIPConnection object can't be used anymore.
       
   374 		*/
       
   375 
       
   376         void CSIPDeleted();
       
   377 
       
   378 
       
   379         /**
       
   380 		* Obtains the initial state for registration state machine.
       
   381         *
       
   382         * @return Initial registration state, ownership is not transferred
       
   383 		*/
       
   384 
       
   385         CRegistrationState* InitialRegisterStateL() const;
       
   386 
       
   387 
       
   388         /**
       
   389 		* Obtains the initial state for dialog state machine.
       
   390         *
       
   391         * @return Initial dialog state, ownership is not transferred
       
   392 		*/
       
   393 
       
   394         CDialogState* InitialDialogStateL() const;
       
   395 
       
   396 
       
   397         /**
       
   398         * Response related to a dialog has been received.
       
   399 		*
       
   400         * @param aElements SIP response elements. Ownership is transferred.
       
   401         * @param aRequestId Identifies the transaction
       
   402         * @param aDialogId DialogId
       
   403         * @param aRefreshId NULL if the response is not related to a refresh,
       
   404         *   otherwise the RefreshId. Ownership is not transferred.
       
   405 		*/
       
   406 
       
   407         void IncomingResponseToDialogL(CSIPResponseElements* aElements,
       
   408 		                               TUint32 aRequestId,
       
   409                                        TUint32 aDialogId,
       
   410                                        TUint32* aRefreshId);
       
   411 
       
   412     private:
       
   413         CSIPConnection(CSIP& aSIP,
       
   414                        TUint32 aIapId,
       
   415                        MSIPConnectionObserver& aObserver);
       
   416 
       
   417         void ConstructL();
       
   418 
       
   419 
       
   420         /**
       
   421         * Send a SIP request.
       
   422         *
       
   423 		* @param aElements SIP headers. Ownership is transferred.
       
   424         * @param aRegistrationId If non-NULL, request will use the outbound
       
   425         *   proxy and some SIP headers from the registration identified by
       
   426         *   aRegistrationId. Ownership is not transferred.
       
   427         * @param aRefresh If non-NULL, the request will be refreshed. Otherwise
       
   428         *   NULL. Ownership is not transferred.
       
   429 		* @return New transaction. Ownership is transferred.
       
   430         */
       
   431 
       
   432         CSIPClientTransaction*
       
   433             SendRequestL(CSIPRequestElements* aElements,
       
   434                          TUint32* aRegistrationId,
       
   435 						 CSIPRefresh* aRefresh);
       
   436 
       
   437 
       
   438         /**
       
   439         * Searches for a refresh and transaction, using aRequestId and
       
   440         * aRefreshId as keys.        
       
   441 		* @param aRequestId RequestId associated with the refreshed transaction
       
   442         * @param aRefreshId RefreshId associated with the refresh instance
       
   443         * @param aRefresh OUT: if refresh was found, this pointer is set to the
       
   444         *   refresh instance. Ownership is not transferred.
       
   445         * @param aTransaction OUT: if transaction was found, this pointer is
       
   446         *   set to the refreshed client transaction. Ownership is not
       
   447         *   transferred.
       
   448 		* @return ETrue if found, EFalse otherwise
       
   449         */
       
   450 
       
   451         TBool FindRefresh(TUint32 aRequestId,
       
   452                           TUint32 aRefreshId,
       
   453                           CSIPRefresh** aRefresh,
       
   454                           CSIPClientTransaction** aTransaction) const;
       
   455 
       
   456         /**
       
   457         * Searches for a registration binding, using aRequestId as a key.
       
   458 		* @param aRequestId RequestId of a transaction associated with the
       
   459         *   registration binding
       
   460 		* @return Found registration binding or NULL if not found.
       
   461 		*	Ownership is not transferred.
       
   462         */
       
   463 
       
   464         CSIPRegistrationBinding* FindRegistration(TUint32 aRequestId) const;
       
   465 
       
   466         
       
   467         /**
       
   468         * Searches for a dialog, using aDialogId as a key.        
       
   469         * @param aDialogId DialogId of the dialog.
       
   470 		* @return Found dialog or NULL if not found. Ownership is not
       
   471         *   transferred.
       
   472         */
       
   473 
       
   474         CSIPDialog* FindDialog(TUint32 aDialogId) const;
       
   475 
       
   476 
       
   477         /**
       
   478         * A request has been received with a dialogId, but no matching dialog
       
   479         * exists.
       
   480 		* If the request is NOTIFY, it is stored until a response with the same
       
   481         * dialogId is received. Then the response is passed to dialog and after
       
   482         * that all the stored NOTIFY are passed to the same dialog.
       
   483         * This is needed since NOTIFY can be received before a sent SUBSCRIBE
       
   484         * receives a response with dialogId.
       
   485 		*
       
   486         * @param aTransaction Server transaction, ownership is transferred
       
   487         * @param aDialogId DialogId
       
   488 		*/
       
   489 
       
   490         void IncomingRequestBeforeDialogExistsL(
       
   491                                     CSIPServerTransaction* aTransaction,
       
   492                                     TUint32 aDialogId);
       
   493 
       
   494 
       
   495         /**
       
   496 		* Extracts the oldest stored transaction for the dialog identified by
       
   497         * aDialogId.
       
   498         * @param aDialogId DialogId
       
   499         * @return Server transaction or NULL if no transaction is stored for
       
   500         *   the dialog. Ownership is transferred.
       
   501 		*/
       
   502 
       
   503         CSIPServerTransaction* GetStoredTransaction(TUint32 aDialogId);
       
   504 
       
   505 
       
   506         /**
       
   507 		* Checks that CSIP is available for use (not NULL). If iSIP is NULL,
       
   508         * it means user has deleted a resource needed by CSIPConnection, and
       
   509         * this function leaves.
       
   510 		*/
       
   511 
       
   512         void CheckCSipL() const;       
       
   513 
       
   514 
       
   515         /**
       
   516 		* Connection is no longer available. All registrations, dialogs,
       
   517         * transactions and refreshes using this connection are terminated, but
       
   518         * not deleted.
       
   519 		*/
       
   520 
       
   521         void ConnectionLost();
       
   522 
       
   523 
       
   524         //The used CSIP instance. CSIPConnection doesn't own the CSIP.
       
   525         //If this pointer is NULL; it means application has deleted the
       
   526         //CSIP instance before deleting the CSIPConnection, and this
       
   527         //CSIPConnection is now useless.
       
   528         CSIP* iSIP;
       
   529 
       
   530         //IAP-id of this connection
       
   531         TUint32 iIapId;
       
   532 
       
   533         //Callback to upper layer
       
   534         MSIPConnectionObserver& iObserver;
       
   535 
       
   536         //Callback receiving events from client
       
   537         CSIPClientConnectionObserver* iClientConnectionObserver;        
       
   538 
       
   539         //Connection used by this CSIPConnection instance
       
   540         CSIPClientConnection* iClientConnection;
       
   541 
       
   542         //CSIPConnection doesn't own CSIPRegistrationBindings
       
   543         RPointerArray<CSIPRegistrationBinding> iRegistrations;
       
   544 
       
   545         //CSIPConnection doesn't delete the CSIPDialog objects. CSIPDialog
       
   546         //deletes itself when its last dialog association is deleted.
       
   547         //NOTE: When CSIPDialog has just been created and has no dialog
       
   548         //associations yet, it must be stored in CleanupStack, otherwise it
       
   549         //won't be freed if leave occurs!
       
   550         RPointerArray<CSIPDialog> iDialogs;
       
   551 
       
   552         //CSIPConnection has to know which transactions are attached to it, but
       
   553         //it doesn't own the transactions. Transaction's ownership is passed
       
   554         //to application.
       
   555         RPointerArray<CSIPTransactionBase> iTransactions;
       
   556 
       
   557         //Standalone refreshes, application owns these
       
   558         RPointerArray<CSIPRefresh> iRefreshes;
       
   559 
       
   560         //To avoid using callbacks to MSIPConnectionObserver from within
       
   561         //CSIPRegistrationBinding and CSIPDialog, CConnectionCallback is passed to
       
   562         //the methods which would need to use MSIPConnectionObserver calls.
       
   563         //CSIPRegistrationBinding and CSIPDialog will fill CConnectionCallback with
       
   564         //the selected callback method and its parameters, and by returning
       
   565         //ETrue they tell to CSIPConnection that a callback has to be done.
       
   566         CConnectionCallback* iCallbackInfo;
       
   567         
       
   568         
       
   569         // Not in real SIP API
       
   570         TState iState;
       
   571 
       
   572         __DECLARE_TEST;
       
   573 
       
   574 #ifdef CPPUNIT_TEST	
       
   575 	    friend class CSIP_Test;
       
   576         friend class CSIPConnection_Test;
       
   577         friend class CSIPSubscribeDialogAssoc_Test;
       
   578         friend class CSIPInviteDialogAssoc_Test;
       
   579         friend class CSIPReferDialogAssoc_Test;
       
   580         friend class CSIPDialogTrying_Test;
       
   581         friend class CSIPRegistrationBinding_Test;
       
   582 #endif
       
   583 	};
       
   584 
       
   585 #endif
       
   586