realtimenetprots/sipfw/SIP/sipapi/api/siphttpdigest.h
author Petteri Saari <petteri.saari@digia.com>
Thu, 25 Nov 2010 13:59:42 +0200
branchMSRP_FrameWork
changeset 58 cdb720e67852
parent 0 307788aac0a8
permissions -rw-r--r--
This release addresses the following issues: 1. The crash bug fix when receiving file 2. Now the sending is based on MSRP messages, there is no longer file receiving or sending. Client sends data as MSRP was designed. 3. Soma MSRP stack was created so that the client told the correct session-id, Symbian stack generated it by itself. This is not allowed, it was changed so that clients tell the session-id (same as used in SIP INVITE). 4. Unnecessary division of data to chunks removed when there is no need to interrupt sending. The message is sent in as few chunks as possible. 5. Stack can now receive files and chunks with ?unlimited? size. Old stack wrote the incoming data to memory and did not utilize disk space until the end of chunk was reached (large chunks from another client crashed it). 6. Now when writing the incoming data to file, it will take into account the byte-range header values. So, this complies with the RFC4975 requirements that stack must be able to handle chunks that come in any sequence. 7. Some buffering changes to outgoing/incoming data. 8. The outgoing data is now checked that it does not contain the created transaction-id before sending the data. 9. MSRP success reports are now implemented and tested against servers. 10. Progress report system fixed so progress is now visible on client (all the way to 100%). 11. Message Cancel receiving / Cancel sending now corrected and made to work as rfc4975 requires. (termination from sender and error code from receiver when cancelling). 12. Bug correction related to messages received not belonging to any session, old stack implementation did send error response, but after response was written it did give the buffer to client anyway. Now corrected.

/*
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
* Name        : siphttpdigest.h
* Part of     : SIP Client
* Interface   : SDK API, SIP Client API
* Version     : 2.0
*
*/



#ifndef CSIPHTTPDIGEST_H
#define CSIPHTTPDIGEST_H

// INCLUDES 
#include <e32base.h>

// FORWARD DECLARATIONS
class CSIP;
class MSIPHttpDigestChallengeObserver;
class MSIPHttpDigestChallengeObserver2;
class CSIPClientTransaction;
class CSIPRefresh;

// CLASS DECLARATION

/**
* @publishedAll
* @released
*
* Class for managing SIP HTTP Digest security settings.
* Class provides functions for setting/removing
* HTTP Digest security mechanism related parameters.
* If the user does not use the class for the providing credentials for the
* received challenges, an error will be returned to the original request in
* case it was challenged.
* 
* Note that the user will be asked to provide credentials one realm
* at the time.
*
*  @lib sipclient.lib
*/
class CSIPHttpDigest : public CBase
	{
	public: // Constructors and destructor
	
		/**
		* Two-phased constructor.
		* @param aSIP a handle to SIP server
		* @param aObserver an observer for the received challenges
		* @return New object, ownership is transferred.
		*/
		IMPORT_C static CSIPHttpDigest*
			NewL(CSIP& aSIP,
				 MSIPHttpDigestChallengeObserver& aObserver);
				 
		/**
		* Two-phased constructor.
		* @param aSIP a handle to SIP server
		* @param aObserver an observer for the received challenges
		* @return New object, ownership is transferred.
		*/
		IMPORT_C static CSIPHttpDigest*
			NewLC(CSIP& aSIP,
				  MSIPHttpDigestChallengeObserver& aObserver);

		/**
		* Two-phased constructor.
		* @param aSIP a handle to SIP server
		* @param aObserver2 an observer for the received challenges
		* @return New object, ownership is transferred.
		*/
		IMPORT_C static CSIPHttpDigest*
			NewL(CSIP& aSIP,
				 MSIPHttpDigestChallengeObserver2& aObserver2);
				 
		/**
		* Two-phased constructor.
		* @param aSIP a handle to SIP server
		* @param aObserver2 an observer for the received challenges
		* @return New object, ownership is transferred.
		*/
		IMPORT_C static CSIPHttpDigest*
			NewLC(CSIP& aSIP,
				  MSIPHttpDigestChallengeObserver2& aObserver2);
				  
		IMPORT_C ~CSIPHttpDigest();

	public: // New functions

        /**
		* Sets credentials for the realm of the outbound proxy.
		* Must be used in case the realm is the realm of the outbound proxy and
		* the request for credentials was received from callback
		* MSIPHttpDigestChallengeObserver::ChallengeReceived.		
		* The user can set credentials only upon request from the
		* SIP implementation.
		* @pre aOutboundProxy, aRealm, aUsername and aPasswd must not be empty
		*	   descriptors.
		* @param aOutboundProxy an outbound proxy (FQDN or IP address)
		* @param aRealm servers's realm
		* @param aUsername user's name
		* @param aPasswd user's password for the given server's realm
		* @leave KErrNoMemory if out of memory
		* @leave KErrArgument if some of the parameters is an empty descriptor
		* @leave KErrSIPResourceNotAvailable if a required object has been
		*		 deleted
		*/
		IMPORT_C void SetCredentialsL(const TDesC8& aOutboundProxy,
			                          const TDesC8& aRealm,
			                          const TDesC8& aUsername,
			                          const TDesC8& aPasswd);
        /**
		* Sets parameters for the realm.
		* Should be used in case the realm is not a realm of an outbound proxy 
		* and the request for credentials was received from callback
		* MSIPHttpDigestChallengeObserver::ChallengeReceived.		
		* The user can set credentials only upon request from the
		* SIP implementation.
		* @pre aRealm, aUsername and aPasswd must not be empty descriptors.
		* @param aRealm servers's realm
		* @param aUsername user's name
		* @param aPasswd user's password for the given server's realm
		* @leave KErrNoMemory if out of memory
		* @leave KErrArgument if some of the parameters is an empty descriptor
		* @leave KErrSIPResourceNotAvailable if a required object has been
		*		 deleted
		*/
		IMPORT_C void SetCredentialsL(const TDesC8& aRealm,
			                          const TDesC8& aUsername,
			                          const TDesC8& aPasswd);

        /**
		* Sets credentials for the realm for the specific transaction.
		* Must be used when the request for credentials was received 
		* from callback MSIPHttpDigestChallengeObserver2::ChallengeReceived with 
		* CSIPClientTransaction as the parameter.
		* @pre aRealm, aUsername and aPasswd must not be empty descriptors.
		* @param aTransaction the transaction that was passed as a parameter
		*        to MSIPHttpDigestChallengeObserver2::ChallengeReceived
		* @param aOutboundProxy an outbound proxy (FQDN or IP address) if
		*        the challenge received had Proxy-Authenticate-header(s).
		*        Otherwise KNullDesC8 should passed.
		* @param aRealm servers's realm
		* @param aUsername user's name
		* @param aPasswd user's password for the given server's realm
		* @leave KErrNoMemory if out of memory
		* @leave KErrArgument if some of the parameters is an empty descriptor
		* @leave KErrSIPResourceNotAvailable if a required object has been
		*		 deleted
		*/
		IMPORT_C void SetCredentialsL(const CSIPClientTransaction& aTransaction,
		                              const TDesC8& aOutboundProxy,
			                          const TDesC8& aRealm,
			                          const TDesC8& aUsername,
			                          const TDesC8& aPasswd);

        /**
		* Sets credentials for the realm for the specific refresh.
		* Must be used when the request for credentials was received 
		* from callback MSIPHttpDigestChallengeObserver2::ChallengeReceived with 
		* CSIPRefresh as the parameter.
		* @pre aRealm, aUsername and aPasswd must not be empty descriptors.
		* @param aRefresh the refresh that was passed as a parameter
		*        to MSIPHttpDigestChallengeObserver2::ChallengeReceived
		* @param aOutboundProxy an outbound proxy (FQDN or IP address) if
		*        the challenge received had Proxy-Authenticate-header(s).
		*        Otherwise KNullDesC8 should passed.
		* @param aRealm servers's realm
		* @param aUsername user's name
		* @param aPasswd user's password for the given server's realm
		* @leave KErrNoMemory if out of memory
		* @leave KErrArgument if some of the parameters is an empty descriptor
		* @leave KErrSIPResourceNotAvailable if a required object has been
		*		 deleted
		*/
		IMPORT_C void SetCredentialsL(const CSIPRefresh& aRefresh,
		                              const TDesC8& aOutboundProxy,
			                          const TDesC8& aRealm,
			                          const TDesC8& aUsername,
			                          const TDesC8& aPasswd);
			            
        /**
		* Removes all set credentials for the realm.
		* Must not be used if the user implements 
		* MSIPHttpDigestChallengeObserver2.
		* @pre aRealm must not be an empty descriptor
		* @param aRealm servers's realm
		* @return KErrNone if no error
		*		  KErrArgument if aRealm is an empty descriptor
		*		  KErrNoMemory if out of memory
		*		  KErrNotFound if the given realm was not found
        */
		IMPORT_C TInt RemoveCredentials(const TDesC8& aRealm);
		
        /**
		* Removes all set credentials by the user.
		* Must not be used if the user implements 
		* MSIPHttpDigestChallengeObserver2.		
		* @return KErrNone if succesful; KErrNoMemory if out of memory 
        */
		IMPORT_C TInt RemoveCredentials();
					                                                        
		/**
		* Sets the observer	to listen for the possible received challenges. 
		* Replaces the existing MSIPHttpDigestChallengeObserver or
		* MSIPHttpDigestChallengeObserver2.
		* @param aObserver an observer for the received challenges. 
		*/
		IMPORT_C void SetObserver(MSIPHttpDigestChallengeObserver& aObserver);
		
		/**
		* Sets the observer	to listen for the possible received challenges. 
		* Replaces the existing MSIPHttpDigestChallengeObserver or
		* MSIPHttpDigestChallengeObserver2.
		* @param aObserver an observer for the received challenges. 
		*/
		IMPORT_C void SetObserver(MSIPHttpDigestChallengeObserver2& aObserver);		
		
		/**
		* Ignores the challenge for the realm. As a result the error will be
		* generated to the original SIP request. 
		* @pre aRealm must not be an empty descriptor
		* @param aRealm a realm for which the challenge was ignored
		* @return KErrNone if no error
		*		  KErrNotFound if the given realm was not found
		*		  KErrArgument if aRealm is an empty descriptor
		*/
		IMPORT_C TInt IgnoreChallenge(const TDesC8& aRealm);

		/**
		* Ignores the challenge for the realm for the specific transaction.
		* As a result KErrForbidden will be generated 
		* to the original SIP request.
		* @pre aRealm must not be an empty descriptor
		* @param aTransaction the transaction that was passed as a parameter
		*        to MSIPHttpDigestChallengeObserver2::ChallengeReceived		
		* @param aRealm a realm for which the challenge was ignored
		* @return KErrNone if no error
		*		  KErrNotFound if the given realm was not found
		*		  KErrArgument if aRealm is an empty descriptor
		*/
		IMPORT_C TInt IgnoreChallenge(const CSIPClientTransaction& aTransaction,
		                              const TDesC8& aRealm);

		/**
		* Ignores the challenge for the realm for the specific refresh.
		* As a result the error will be generated 
		* to the original SIP request.
		* @pre aRealm must not be an empty descriptor
		* @param aRefresh the refresh that was passed as a parameter
		*        to MSIPHttpDigestChallengeObserver2::ChallengeReceived		
		* @param aRealm a realm for which the challenge was ignored
		* @return KErrNone if no error
		*		  KErrNotFound if the given realm was not found
		*		  KErrArgument if aRealm is an empty descriptor
		*/
		IMPORT_C TInt IgnoreChallenge(const CSIPRefresh& aRefresh,
		                              const TDesC8& aRealm);

	public: // New functions, for internal use

		void CSIPDeleted();

	private: // Constructors

        CSIPHttpDigest(CSIP& aSIP);
		CSIPHttpDigest(const CSIPHttpDigest& aHttpDigest);
		CSIPHttpDigest& operator=(const CSIPHttpDigest& aHttpDigest);

		void ConstructL(MSIPHttpDigestChallengeObserver& aObserver);
		
		void ConstructL(MSIPHttpDigestChallengeObserver2& aObserver2);
       
    private: // New functions
    
		TInt RemoveCredentialParams(const TDesC8& aRealm) const;

		void SetCredentialParamsL(TUint32 aRequestId,
		                          TUint32 aRefreshId,
		                          const TDesC8& aOutboundProxy,
		                          const TDesC8& aRealm,
				                  const TDesC8& aUsername,
				                  const TDesC8& aPasswd) const;		
		
		TInt IgnoreChallenge(TUint32 aRequestId,
		                     TUint32 aRefreshId,
		                     const TDesC8& aRealm);       
          
    private: // Data

        CSIP* iSIP;

	private: // For testing purposes
#ifdef CPPUNIT_TEST
	    friend class CSIP_Test;
#endif
	};

#endif // CSIPHTTPDIGEST_H