realtimenetprots/sipfw/ProfileAgent/profile_fsm/inc/sipprofilecontextbase.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        : sipprofilecontextbase.h
       
    16 * Part of     : sip profile fsm
       
    17 * Interface   : internal interface
       
    18 * Version     : %version: 2.1.1 %
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 /**
       
    26  @internalComponent
       
    27 */
       
    28 
       
    29 #ifndef CSIPPRROFILECONTEXTBASE_H
       
    30 #define CSIPPRROFILECONTEXTBASE_H
       
    31 
       
    32 //INCLUDES 
       
    33 #include <e32base.h>
       
    34 #include <badesca.h>
       
    35 #include "sipconnection.h"
       
    36 #include "sipclienttransaction.h"
       
    37 #include "sipregistrationbinding.h"
       
    38 #include "sipprofilecontext.h"
       
    39 #include "sipprofileagent.h"
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 class CSIP;
       
    43 class CSIPHttpDigest;
       
    44 
       
    45 // CLASS DECLARATION
       
    46 /**
       
    47 *  A base class for maintaining the dynamic information related
       
    48 *  to a particular SIP profile. Class stores the related registration, 
       
    49 *  sip connection and transactions.
       
    50 *
       
    51 *  @lib sipprofilefsm.lib
       
    52 */
       
    53 class CSIPProfileContextBase : public CBase, public MSIPProfileContext
       
    54 	{
       
    55 	public:
       
    56 
       
    57         /**
       
    58         * Destructor.
       
    59         */
       
    60 		IMPORT_C virtual ~CSIPProfileContextBase();
       
    61 
       
    62 
       
    63     public: // From MSIPProfileContext
       
    64     
       
    65         IMPORT_C const CSIPConnection& Connection() const; 
       
    66         
       
    67         IMPORT_C CSIPRegistrationBinding* Registration();
       
    68         
       
    69         IMPORT_C void SetNextState(CSIPPrflStateBase& aState);
       
    70 
       
    71         IMPORT_C void ForgetProfile();
       
    72 
       
    73         IMPORT_C void SetTransaction(CSIPClientTransaction* aTransaction);
       
    74 
       
    75         IMPORT_C CSIPConcreteProfile* Profile();
       
    76 
       
    77         IMPORT_C virtual MSIPProfileAgentObserver& AgentObserver() const;
       
    78 
       
    79         IMPORT_C void SetProfile(CSIPConcreteProfile* aProfile);
       
    80         
       
    81         IMPORT_C TInt SetRegisteredAORs();	
       
    82         
       
    83         IMPORT_C void RemoveDeltaTimerEntry();
       
    84         
       
    85         IMPORT_C void HandleProxyResolvingError(TInt aError);
       
    86         
       
    87         IMPORT_C TBool IsProxyResolvingEnabled() const;
       
    88         
       
    89         IMPORT_C TBool ProxiesAlreadyResolved();
       
    90         
       
    91         IMPORT_C void SetProxiesL(MDesC8Array& aProxies);
       
    92        
       
    93 		IMPORT_C void SetNegotiatedSecurityMechanismL();
       
    94 		
       
    95 		IMPORT_C void ResetNegotiatedSecurityMechanismL();       
       
    96         
       
    97 	public: // New functions
       
    98 
       
    99 		/**
       
   100 		* Gets the current SIP Profile FSM state
       
   101 		* @return current state
       
   102 		*/
       
   103 		IMPORT_C TSIPProfileState CurrentState() const;
       
   104 
       
   105 		/**
       
   106 		* Gets the current state mapped to the state of CSIPConcreteProfile  
       
   107 		* @return the current mapped state
       
   108 		*/
       
   109         IMPORT_C CSIPConcreteProfile::TStatus CurrentMappedState() const;
       
   110 
       
   111 	    /**
       
   112 	    * Registers SIP profile to the network and maintains
       
   113 	    * the registration. Takes actions needed for the registration
       
   114         * according to the profile type.
       
   115 	    */
       
   116 	    IMPORT_C void RegisterL();
       
   117 
       
   118         /**
       
   119         * Checks whether a registration is pending for the profile.
       
   120         * In other words if a REGISTER has been sent 
       
   121         * but a final response has not yet been received.
       
   122         */ 		
       
   123         IMPORT_C TBool IsRegisterPending() const;
       
   124 
       
   125 		/**
       
   126 		* Retries registration with next proxy address if needed
       
   127 		*/
       
   128 		IMPORT_C void RetryRegistration();
       
   129 
       
   130 		/**
       
   131 		* Sets resolved proxy addresses
       
   132 		* @param aProxies array of dynamicly resolved proxies
       
   133 		*/
       
   134 		IMPORT_C void ProxyResolvingRequestCompleteL(MDesC8Array& aProxies);
       
   135 
       
   136 		/**
       
   137 		* An asynchronous proxy resolving request has failed.
       
   138 		* @param aError a reason why the request failed.
       
   139 		*/
       
   140 		IMPORT_C void ProxyResolvingRequestFailed(TInt aError);
       
   141 
       
   142 		/**
       
   143 		* Checks if error event is ignored and not sent to client
       
   144 		* @return ETrue if error can ignored
       
   145 		*/
       
   146 		IMPORT_C TBool IgnoreErrorEvent();
       
   147 		
       
   148 		/**
       
   149 		* Terminates abnormally profile handling i.e.
       
   150 		* cleanups reserved resources for the profile and forgets it.
       
   151 		*/
       
   152 		IMPORT_C void TerminateHandling();		
       
   153 
       
   154 		/**
       
   155 		* An asynchronous error has occured related to a periodical refresh 
       
   156 		* that relates to a registration.
       
   157 		* @param aError error code
       
   158 		* @param aRegistration associated registration
       
   159 		* @param aHandled, returned ETrue if response handled
       
   160 		*/
       
   161 		IMPORT_C void ErrorOccured(TInt aError,
       
   162 		                           CSIPRegistrationBinding& aRegistration,
       
   163 		                           TBool& aHandled);
       
   164 
       
   165 		/**
       
   166 		* An asynchronous error has occurred in the stack related
       
   167 		* to the request indicated by the given transaction.
       
   168 		* @param aError error code
       
   169 		* @param aTransaction the failed transaction
       
   170 		* @param aRegistration the failed registration
       
   171 		* @param aHandled, returned ETrue if response handled
       
   172 		*/
       
   173 		IMPORT_C void ErrorOccured(TInt aError,
       
   174 		                           CSIPClientTransaction& aTransaction,
       
   175 		                           CSIPRegistrationBinding& aRegistration,
       
   176 		                           TBool& aHandled);
       
   177 
       
   178 		/**
       
   179 		* Connection state has changed.
       
   180 		* @param aState indicates the current connection state
       
   181 		*/
       
   182 		IMPORT_C void ConnectionStateChanged(CSIPConnection::TState aState);
       
   183 
       
   184 		IMPORT_C void RetryDeltaTimer( TUint aTime, TInt aError );
       
   185 		
       
   186 		/**
       
   187 		* Checks if profile has not received final response to 
       
   188 		* registration/deregistration and the registrar has same value
       
   189 		* as input value aValue
       
   190 		* @return ETrue if conditions are met.
       
   191 		*/
       
   192 		IMPORT_C TBool AddIntoQueue( const TDesC8& aValue );
       
   193 		
       
   194 		/**
       
   195 		* Checks if profile is in state when register has not yet been sent
       
   196 		* @return ETrue if conditions are met.
       
   197 		*/
       
   198 		IMPORT_C TBool AddDeregisterIntoQueue();
       
   199 		
       
   200 		/**
       
   201 		* Checks if the profile  is in idle state.
       
   202 		* @return ETrue if conditions are met.
       
   203 		*/
       
   204 		IMPORT_C TBool IsIdle();
       
   205 
       
   206 		/**
       
   207 		* Sets HTTP Digest credentials from the profile
       
   208 		* if the given transaction is related to this profile.
       
   209 		* @return ETrue if the transaction was found and credentials were set.
       
   210 		*/
       
   211         IMPORT_C TBool SetCredentials(
       
   212             const CSIPClientTransaction& aTransaction,
       
   213             CSIPHttpDigest& aDigest);
       
   214 
       
   215 		/**
       
   216 		* Sets HTTP Digest credentials from the profile
       
   217 		* if the given refresh is related to this profile.
       
   218 		* @return ETrue if the refresh was found and credentials were set.
       
   219 		*/
       
   220         IMPORT_C TBool SetCredentials(
       
   221             const CSIPRefresh& aRefresh,
       
   222             CSIPHttpDigest& aDigest);
       
   223 
       
   224     public: // For internal use
       
   225 
       
   226 		static TInt RetryDeltaTimerExpired(TAny* aPtr);
       
   227 		
       
   228 		void ContinueRegistrationL();
       
   229 
       
   230 	protected: // Constructors
       
   231 	
       
   232 		/**
       
   233 		* Constructor
       
   234 		*/
       
   235 		IMPORT_C CSIPProfileContextBase(
       
   236 			CSIP& aSIP,
       
   237 			CSIPConnection& iConnection,
       
   238 			MSIPProfileAgentObserver& aObserver,
       
   239 			CSIPPrflStateBase& aInitState,
       
   240 			CSIPConcreteProfile& aProfile,
       
   241 			CDeltaTimer& aDeltaTimer);
       
   242     
       
   243     protected: // Virtual functions
       
   244 
       
   245     	IMPORT_C virtual TBool HasTransaction(
       
   246     	    const CSIPClientTransaction& aTransaction) const;
       
   247     
       
   248     	IMPORT_C virtual TBool HasRefresh(
       
   249     	    const CSIPRefresh& aRefresh) const;
       
   250     	    
       
   251     	IMPORT_C virtual const TDesC8& RegistrarUsername() const;
       
   252 
       
   253 		virtual void ConnectionStateChangedImpl(
       
   254 		    CSIPConnection::TState aState) = 0;
       
   255 		    
       
   256 		virtual void SetRegisteredAORsL() = 0;
       
   257 
       
   258 		virtual TBool RetryRegister(CSIPClientTransaction* aTransaction,
       
   259 							        TInt aError) = 0;
       
   260 							  
       
   261 		virtual TBool ShouldRetryRegistration(TInt aError) = 0;					  
       
   262     	
       
   263     	virtual void InitializeRetryTimerValue() = 0;
       
   264     
       
   265     protected: // New functions
       
   266     
       
   267  		/**
       
   268 		* Require dynamic proxy resolving
       
   269 		* @return ETrue, if required
       
   270 		*/
       
   271 		IMPORT_C TBool RequireProxyResolving();
       
   272     
       
   273 		/**
       
   274 		* Returns either static or dynamic proxy address
       
   275 		* @return proxy address
       
   276 		*/
       
   277 		IMPORT_C const TDesC8& ProxyAddressL();
       
   278 
       
   279 		/**
       
   280 		* Returns either static or dynamic proxy address
       
   281 		* @return proxy address
       
   282 		*/
       
   283 		IMPORT_C const TDesC8& ProxyAddressL(CSIPConcreteProfile& aProfile);
       
   284 		
       
   285 		/**
       
   286 		* A 2XX response to a REGISTER request was received.
       
   287 		*/
       
   288 		IMPORT_C void Received2XXRegisterResponse();
       
   289 		
       
   290 		/**
       
   291 		* Checks if retry of registration is possible
       
   292 		* @return ETrue if retry possible
       
   293 		*/
       
   294 		IMPORT_C TBool RetryPossible(TInt aError);		
       
   295 				
       
   296 		/**
       
   297 		* Set flag to indicate whether retry of registration is possible
       
   298 		* @param aRetryPossible ETrue if retry possible
       
   299 		*/
       
   300 		IMPORT_C void SetRetryPossible(TBool aRetryPossible);
       
   301 		
       
   302 		/**
       
   303 		 * Returns profile ID
       
   304 		 * @return profile ID or 0 if profile doesn't exist
       
   305 		 */
       
   306 		IMPORT_C TUint32 ProfileId() const;
       
   307 		
       
   308     private: // New functions
       
   309 
       
   310         void RegisterDynamicL(MDesC8Array& aProxies);
       
   311 
       
   312 		void ConstructDynamicProxyL(const TDesC8& aProxy);
       
   313 		
       
   314 		void ClearProxyResolving();
       
   315 		
       
   316 		void ResetRegisteredAORsL();				
       
   317  
       
   318         template<class T> void SetCredentialsImplementation(
       
   319             const T& aChallengeTarget,
       
   320             const CSIPResponseElements& aResponse,
       
   321             CSIPHttpDigest& aDigest);
       
   322  
       
   323         TBool GetRegistrarCredentials(
       
   324             TPtrC8& aUsername,
       
   325             TPtrC8& aPassword) const;
       
   326  
       
   327          TBool GetProxyCredentials(
       
   328             TPtrC8& aProxyHost,
       
   329             TPtrC8& aUsername,
       
   330             TPtrC8& aPassword) const;
       
   331  
       
   332         TPtrC8 ExtractProxyHost() const;
       
   333 
       
   334 
       
   335     protected: // Data
       
   336 
       
   337 		CSIP&						iSIP;
       
   338 		CSIPConnection&             iConnection;
       
   339 		MSIPProfileAgentObserver&	iObserver;
       
   340 		CSIPPrflStateBase*			iCurrentState; // Not owned
       
   341 		CSIPPrflStateBase*			iInitState; // Not owned
       
   342 		CSIPConcreteProfile*		iProfile; // Not owned
       
   343 		CSIPClientTransaction*		iClientTx; // Owned
       
   344 		CSIPRegistrationBinding*	iRegistration; // Owned
       
   345 		TUint32						iProfileId;
       
   346 		CDeltaTimer&				iDeltaTimer;
       
   347 		MDesC8Array*				iProxies; // Owned
       
   348 		TInt                        iErrorForDeltaTimer;
       
   349 
       
   350 	private:
       
   351 	
       
   352 		TInt						iDynamicProxyCount;
       
   353 		TCallBack					iDeltaTimerCallBack;
       
   354 		TDeltaTimerEntry			iDeltaTimerEntry;
       
   355 		TBool					    iRetryPossible;
       
   356 		TBool						iResolvingCompleted;
       
   357         RStringF                    iWwwAuthenticateHeaderName;
       
   358         RStringF                    iProxyAuthenticateHeaderName;
       
   359         TBool 						iUseBackupProxy;
       
   360 		
       
   361 	private: // For testing purposes
       
   362 	
       
   363         #ifdef CPPUNIT_TEST	
       
   364 	    	friend class CSIPProfileContextBaseTest;
       
   365         #endif
       
   366 	};
       
   367 
       
   368 #endif // CSIPPRROFILECONTEXTBASE_H
       
   369