realtimenetprots/sipfw/ProfileAgent/IETF_Agent/inc/sipietfconnectioncontext.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2003-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        : sipietfconnectioncontext.h
       
    16 * Part of     : sip ietf agent
       
    17 * Interface   : 
       
    18 * Version     : 1.0
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 /**
       
    26  @internalComponent
       
    27 */
       
    28 
       
    29 #ifndef	CSIPIETFCONNECTIONCONTEXT_H
       
    30 #define CSIPIETFCONNECTIONCONTEXT_H
       
    31 
       
    32 //  INCLUDES
       
    33 #include <e32base.h>
       
    34 #include <bamdesca.h>
       
    35 #include "sipconnectionobserver.h"
       
    36 #include "MSIPProxyResolverObserver.h"
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 class CSIPIetfProfileContext;
       
    40 class CSIPRegistrationBinding;
       
    41 class CSIPClientTransaction;
       
    42 class CSIPDialogAssocBase;
       
    43 class CSIPProxyResolver;
       
    44 class CSIPHttpDigest;
       
    45 class MSIPHttpDigestChallengeObserver2;
       
    46 class CSIPConcreteProfile;
       
    47 class CSIP;
       
    48 class MSIPObserver;
       
    49 
       
    50 // CLASS DECLARATION
       
    51 
       
    52 /**
       
    53 * Class maintains associations between the SIP connection
       
    54 * and related SIP profiles. 
       
    55 * 
       
    56 */
       
    57 class CSIPIetfConnectionContext: public CBase, public MSIPConnectionObserver,
       
    58 	public MSIPProxyResolverObserver
       
    59 	{
       
    60 	public: // Constructors and destructor
       
    61 		   
       
    62         /**
       
    63         * Two-phased constructor.
       
    64         */
       
    65 		static CSIPIetfConnectionContext* NewL();
       
    66 
       
    67         /**
       
    68         * Two-phased constructor.
       
    69         */
       
    70 		static CSIPIetfConnectionContext* NewLC();
       
    71 
       
    72         /**
       
    73         * Destructor.
       
    74         */
       
    75 		~CSIPIetfConnectionContext();
       
    76 
       
    77 	public://new functions
       
    78 
       
    79 	    /**
       
    80 	    * Gets connection, the ownership is not transferred
       
    81 	    * @return connection
       
    82 	    */
       
    83 		CSIPConnection* Connection();
       
    84 
       
    85 	    /**
       
    86 	    * Add profile context, ownership transferred
       
    87 	    * @param aContext, profile context using the connection
       
    88 	    */
       
    89 		void AddProfileContextL(CSIPIetfProfileContext* aContext);
       
    90 
       
    91 	    /**
       
    92 	    * Find context of the profile, the ownership is not transferred
       
    93 	    * @param aProfileId, profile stored in context
       
    94 	    */
       
    95 		CSIPIetfProfileContext* FindContext(TUint32 aProfileId);
       
    96 
       
    97 	    /**
       
    98 	    * Delete idle contexts
       
    99 	    */
       
   100 		void CleanIdleContexts();
       
   101 
       
   102 	    /**
       
   103 	    * Set connection for the context
       
   104 	    * @param aConnection, connection of the context
       
   105 	    */
       
   106 		void SetConnection(CSIPConnection* aConnection);
       
   107 
       
   108 	    /**
       
   109 	    * Checks if connection idle
       
   110 	    * @return ETrue, if contains no profile contexts, otherwise EFalse
       
   111 	    */
       
   112 		TBool IsIdle() const;
       
   113 
       
   114 		/**
       
   115 	    * starts resolving proxy
       
   116 	    */
       
   117 		void ResolveL();
       
   118 
       
   119 		/**
       
   120 		* Cleans dynamic proxy addesses and cancels any
       
   121 		* pending requests
       
   122 		*/
       
   123 		void CleanProxyResolving();
       
   124 		
       
   125 		/**
       
   126 		* Checks if registration/deregistration should be put
       
   127 		* in que to wait, because there is registration/deregistration
       
   128 		* with same registrar address pending.
       
   129 		* @return ETrue if should be put into que to wait.
       
   130 		*/
       
   131 		TBool AddIntoQueue( const TDesC8& aValue );
       
   132 
       
   133 		/**
       
   134 		* Sets HTTP Digest credentials from the profile
       
   135 		* if the given transaction was found from one 
       
   136 		* of the profiles related to this connection.
       
   137 		* @return ETrue if the transaction was found and credentials were set.
       
   138 		*/
       
   139         TBool SetCredentials(
       
   140             const CSIPClientTransaction& aTransaction,
       
   141             CSIPHttpDigest& aDigest);
       
   142 
       
   143 		/**
       
   144 		* Sets HTTP Digest credentials from the profile
       
   145 		* if the given refresh was found from one 
       
   146 		* of the profiles related to this connection.
       
   147 		* @return ETrue if the refresh was found and credentials were set.
       
   148 		*/
       
   149         TBool SetCredentials(
       
   150             const CSIPRefresh& aRefresh,
       
   151             CSIPHttpDigest& aDigest);
       
   152         
       
   153         /**
       
   154         * Checks if this connection is used by given profile.
       
   155         * @param aProfile
       
   156         * @return ETrue if connection is used by profile
       
   157         */    
       
   158         TBool ConnectionUser( CSIPConcreteProfile& aProfile );
       
   159         
       
   160         /**
       
   161         * Attaches conection user.
       
   162         * @pre connection must be set, otherwise leaves with KErrNotReady
       
   163         * @param aProfile
       
   164         */
       
   165         void SetConnectionUserL( CSIPConcreteProfile& aProfile );
       
   166         
       
   167         /**
       
   168         * Creates CSIP and CSIPHttpDigest used for this connection
       
   169         * @param aSipObserver, SIP observer
       
   170         * @param aSipHttpDigestObserver, SIP HTTP Digest challenge observer
       
   171         */
       
   172         CSIP& CreateSipL( 
       
   173             MSIPObserver& aSipObserver,
       
   174             MSIPHttpDigestChallengeObserver2& aSipHttpDigestObserver );
       
   175 
       
   176 	public://functions from base class
       
   177 
       
   178 		/**
       
   179 		* A SIP request outside a dialog has been received from the network.
       
   180 		* @param aTransaction SIP server transaction
       
   181 		* The ownership is transferred.
       
   182         */
       
   183 		void IncomingRequest(CSIPServerTransaction* aTransaction);
       
   184 
       
   185 		/**
       
   186 		* A SIP request within a dialog has been received from the network.
       
   187 		* The client must resolve the actual dialog association to which
       
   188 		* this request belongs.
       
   189 		* @param aTransaction SIP server transaction
       
   190 		* The ownership is transferred.
       
   191 		* @param aDialog the dialog  that
       
   192 		*        this transaction belongs to.
       
   193  		*/
       
   194 		void IncomingRequest(
       
   195             CSIPServerTransaction* aTransaction,
       
   196             CSIPDialog& aDialog);
       
   197 
       
   198 		/**
       
   199 		* A SIP response received from the network.
       
   200 		* @param aTransaction contains response elements.
       
   201 		* The ownership is transferred.
       
   202 		*/
       
   203 		void IncomingResponse(CSIPClientTransaction& aTransaction);
       
   204 
       
   205 		/**
       
   206 		* A SIP response that is within a dialog association or creates
       
   207 		* a dialog association.
       
   208 		* @param aTransaction contains response elements.
       
   209 		* The ownership is transferred.
       
   210 		* @param aDialogAssoc a dialog association
       
   211 		*/
       
   212 		void IncomingResponse(
       
   213             CSIPClientTransaction& aTransaction,
       
   214         	CSIPDialogAssocBase& aDialogAssoc);
       
   215 
       
   216 		/**
       
   217 		* A SIP response creating a registration binding or an error response 
       
   218 		* that is related to an refreshed registration binding  
       
   219 		* has been received from the network.
       
   220 		* @param aTransaction contains response elements.
       
   221 		* The ownership is transferred.
       
   222 		* @param aSIPRegistration associated registration
       
   223 		*/
       
   224 		void IncomingResponse(
       
   225         	CSIPClientTransaction& aTransaction,
       
   226         	CSIPRegistrationBinding& aRegistration);
       
   227 
       
   228 		/**
       
   229 		* A SIP response related a registration binding or an error response
       
   230 		* that is related to registration binding has been received
       
   231         * from the network.
       
   232         *
       
   233 		* @param aTransaction contains response elements.
       
   234 		* @param aRegistration registration this transaction belongs to
       
   235 		*/
       
   236 		void IncomingResponse(
       
   237         	CSIPClientTransaction& aTransaction,
       
   238             CSIPInviteDialogAssoc* aDialogAssoc);
       
   239 
       
   240 		/**
       
   241 		* An asynchronous error has occured related to a periodical refresh 
       
   242 		* that relates to a registration.
       
   243 		* @param aError error code
       
   244 		* @param aSIPRegistration associated registration
       
   245 		*/
       
   246 		void ErrorOccured(
       
   247             TInt aError,
       
   248             CSIPRegistrationBinding& aRegistration);
       
   249 		/**
       
   250 		* An asynchronous error has occurred in the stack related
       
   251 		* to the request indicated by the given transaction.
       
   252 		* @param aError error code
       
   253 		* @param aTransaction the failed transaction
       
   254 		* @param aRegistration the failed registration
       
   255 		*/
       
   256 		void ErrorOccured(
       
   257             TInt aError,
       
   258             CSIPClientTransaction& aTransaction,
       
   259             CSIPRegistrationBinding& aRegistration);
       
   260 
       
   261 		/**
       
   262 		* An asynchronous error has occurred in the stack related to the
       
   263 		* request indicated by the given transaction.
       
   264 		* @param aError error code
       
   265 		* @param aTransaction failed transaction
       
   266 		*/
       
   267 		void ErrorOccured (
       
   268             TInt aError,
       
   269         	CSIPTransactionBase& aTransaction);
       
   270 	
       
   271 		/**
       
   272 		* An asynchronous error has occured related to a request within
       
   273 		* an existing dialog.
       
   274 		* @param aError error code
       
   275 		* @param aTransaction the failed transaction
       
   276 		* @param aDialogAssoc the failed dialog associoation
       
   277 		*/
       
   278 		void ErrorOccured(
       
   279         	TInt aError,
       
   280             CSIPTransactionBase& aTransaction,
       
   281             CSIPDialogAssocBase& aDialogAssoc);
       
   282 
       
   283 		/**
       
   284 		* An asynchronous error has occured related to a refresh 
       
   285 		* @param aError error code
       
   286 		* @param aSIPRefresh original refresh object
       
   287 		*/
       
   288 		void ErrorOccured (
       
   289         	TInt aError,
       
   290         	CSIPRefresh& aRefresh);
       
   291 
       
   292 		/**
       
   293 		* An asynchronous error has occured related to a periodical refresh 
       
   294 		* that belongs to SIP dialog association.
       
   295 		* @param aError error code
       
   296 		* @param aDialogAssoc SIP dialog association
       
   297 		*/
       
   298 		void ErrorOccured(
       
   299             TInt aError,
       
   300             CSIPDialogAssocBase& aDialogAssoc);
       
   301 
       
   302 		/**
       
   303 		* Connection state has changed.
       
   304 		* @param aState indicates the current connection state
       
   305 		*/
       
   306 		void ConnectionStateChanged(CSIPConnection::TState aState);
       
   307 
       
   308         /**
       
   309 		* SIP stack has completed UAC core INVITE transaction 64*T1 seconds
       
   310         * after the reception of the first 2xx response. No more 2xx responses
       
   311         * can be received to the issued single INVITE.
       
   312         *
       
   313 		* @param aTransaction a complete UAC core INVITE transaction
       
   314 		*/
       
   315         void InviteCompleted(CSIPClientTransaction& aTransaction);
       
   316         
       
   317         /**
       
   318         * Invite was canceled with the CANCEL
       
   319         * @param aTransaction a canceled INVITE UAS transaction
       
   320         */
       
   321         void InviteCanceled(CSIPServerTransaction& aTransaction);
       
   322 
       
   323 
       
   324 		/**
       
   325 		* An asynchronous proxy resolving request has been completed.
       
   326 		* @param aRequestId the id of the resolving request.
       
   327 		* @param aProxies a list of proxy addresses.
       
   328 		*        The ownership is transferred.
       
   329 		*/
       
   330 		void ProxyResolvingRequestComplete(
       
   331 		    TUint aRequestId, 
       
   332 		    MDesC8Array* aProxies);
       
   333 
       
   334 		/**
       
   335 		* An asynchronous proxy resolving request has failed.
       
   336 		* @param aRequestId the id of the resolving request.
       
   337 		* @param aError a reason why the request failed.
       
   338 		*/
       
   339 		void ProxyResolvingRequestFailed(TUint aRequestId, TInt aError);
       
   340 
       
   341 		/**
       
   342 	    * starts resolving proxy
       
   343 	    */
       
   344 		void ResolveProxyL();
       
   345 
       
   346 	private:
       
   347 		/**
       
   348 		* Default constructor.
       
   349 		*/
       
   350 		CSIPIetfConnectionContext();
       
   351 
       
   352 		/**
       
   353 		* By default Symbian 2nd phase constructor is private.
       
   354 		*/
       
   355 		void ConstructL();
       
   356 
       
   357     private:
       
   358     
       
   359         void SetConnectionParameters();
       
   360 
       
   361 	private: // Data
       
   362 	
       
   363 		CSIPConnection* iConnection;
       
   364 
       
   365 		CSIPProxyResolver* iProxyResolver;
       
   366 		TUint iProxyResolveRequestId;
       
   367 
       
   368 		RPointerArray<CSIPIetfProfileContext> iContexts;
       
   369 		
       
   370 		RPointerArray<CSIPConcreteProfile> iUsers;
       
   371 		
       
   372 		CSIP* iSip;
       
   373 		CSIPHttpDigest* iSipHttpDigest;
       
   374 		
       
   375 		TBool iConnectionParamsSet;
       
   376 	private: //Unit test classes are declared as friend
       
   377 #ifdef CPPUNIT_TEST
       
   378 		friend class CSIPIetfProfileContextTest;
       
   379 		friend class CSIPIetfConnectionContextTest;
       
   380 #endif
       
   381 	};
       
   382 
       
   383 #endif // CSIPIETFCONNECTIONCONTEXT_H