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