ipappprotocols_plat/srtp_api/inc/srtpstreamout.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) 2004 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:    Represents a sender(outgoing) SRTP stream.
*
*/




#ifndef __SRTP_STREAM_OUT_H__
#define __SRTP_STREAM_OUT_H__

// INCLUDES
#include <e32def.h>
#include "srtpstream.h"
#include "msrtpstreamoutcontext.h"


// FORWARD DECLARATIONS
class CSRTPSession;
class CSRTPCryptoContext;
class MSRTPReKeyingObserver;
class TSRTPStreamOutStateBase;

/**
* Represents an SRTP stream.
*/
class CSRTPStreamOut : public CSRTPStream, 
					   public MSRTPStreamOutContext
    {
    public:
        /**
        * Two-phased constructor.
        * Use this function if the stream will use the SRTP session's default
        * cryptographic context.
        * @param aSession  The session containing the cryptographic
        *   context for this object.
        * @param aSSRC  The synchronization source ID of the RTP stream
        *   that corresponds to this object.
        * @leave KErrNone if success, system-wide error code otherwise
        */
    	IMPORT_C static CSRTPStreamOut* NewL( CSRTPSession& aSession, TUint aSSRC );

        /**
        * Two-phased constructor.
        * Use this function if the stream will have its own cryptographic
        * context.
        * @param aSession  The session containing the cryptographic
        *   context for this object.
        * @param aSSRC  The synchronization source ID of the RTP stream
        *   that corresponds to this object.
        * @param aCon  The cryptographic context, ownership is transfered. 
        * @param aObs  The callback object
        * @leave KErrNone if success, system-wide error code otherwise
        */
    	IMPORT_C static CSRTPStreamOut* NewL( CSRTPSession& aSession,
                                       TUint aSSRC,
                                       CSRTPCryptoContext* aCon,
                                       MSRTPReKeyingObserver& aObs );
        
        /**
        * Two-phased constructor.
        * Use this function if the stream will have its own cryptographic
        * context. Note that if crypto context is not set later, all data
        * packet will not be processed.
        * @param aSession  The session containing the cryptographic
        *   context for this object.
        * @param aSSRC  The synchronization source ID of the RTP stream
        *   that corresponds to this object.
        * @param aCon  The cryptographic context 
        * @param aObs  The callback object
        * @leave KErrNone if success, system-wide error code otherwise
        */
    	IMPORT_C static CSRTPStreamOut* NewL( CSRTPSession& aSession,
                                       TUint aSSRC,
                                       MSRTPReKeyingObserver& aObs );                                       
	
    public:
        /**
        * Protect an RTP packet.
        * The settings for the protection are fetched from the appropriate
        * cryptographic context. If the protection fails, the function leaves
        * with a system error code and the provided RTP packet is unaltered.
        * @param aPacket  The RTP packet to protect. The length of descriptor
        *  should be the same with the actual data, otherwise encoding will not be 
        *  correct.
        * @leave KErrNone if success, system-wide error code otherwise
        * @return An SRTP packet.
        */
        IMPORT_C HBufC8* ProtectRtpL( const TDesC8& aPacket );

        /**
        * Protect an RTCP packet.
        * The settings for the protection are fetched from the appropriate
        * cryptographic context. If the protection fails, the function leaves
        * with a system error code and the provided RTCP packet is unaltered.
        * @param aPacket  The RTCP packet to protect.
        * @leave KErrNone if success, system-wide error code otherwise
        * @return An SRTCP packet.
        */
        IMPORT_C HBufC8* ProtectRtcpL( const TDesC8& aPacket );

        /**
        * Set CryptoContext for OutStream
        * Setting cryptographic context must be done to enable encode/decode packets.
        * During offer/Answer, offerer do not know which crypto context is 
        * chosen by answerer. CryptoContext then can be set after getting response
        * from answerer.
        * Updating stream specific crypto Context. 
        * Note that to update crypto context, ROC will not be re-intialed to zero but 
        * the states and number of receiving packets will be reset. This can be 
        * use only when keys lifetime has not expired.
        * Crypto context ownershíp is transfered.
        * @param aCon aCryyptoContext which wants be used
        * @leave KErrNone if success, system-wide error code otherwise
        * @return void
        */        
        IMPORT_C void SetCryptoOutL(CSRTPCryptoContext* aCon);
        
         ~CSRTPStreamOut( );    
         
       	/**
        * Delete the existed crypto context and re-initial the states
        * @param None
        * @leave KErrNone if success, system-wide error code otherwise
        * @return void
        */        
		void UpdateCryptoAndStatesL();
		   
    private:  //from MSRTPStreamOutContext

        /*
        * Change state of the current outgoing stream (for RTP)
        * @return void.
        */
        void ChangeRTPState(MSRTPStreamOutContext::TContextOutState aNewState);

        /*
        * Change state of the current outgoing stream (for RTCP)
        * @return void.
        */
        void ChangeRTCPState(MSRTPStreamOutContext::TContextOutState aNewState/*TState aNewState*/);        

    private:  //methods
        CSRTPStreamOut (CSRTPSession& aSession,
                       TUint aSSRC);

        CSRTPStreamOut (CSRTPSession& aSession,
                       TUint aSSRC,
                       CSRTPCryptoContext* aCon,
                       MSRTPReKeyingObserver& aObs );
                       
        CSRTPStreamOut (CSRTPSession& aSession,
                       TUint aSSRC,
                       MSRTPReKeyingObserver& aObs );
               

        void ConstructL();
        
        /**
        * Create states defined in TSRTPStreamOutStateBase
        * @leave KErrNone if success, system-wide error code otherwise
        * @return void.
        */
        void InitializeStatesL();

        TSRTPStreamOutStateBase& CurrentRTPState();

        TSRTPStreamOutStateBase& CurrentRTCPState();
                       
    protected:
        /*
        states for CSRTPStreamOut
        */
	    CArrayVarFlat<TSRTPStreamOutStateBase> iStates;
        /*
        the same stream can handle RTP and RTCP packets,
        these can have different states
        */
	    MSRTPStreamOutContext::TContextOutState iCurrentRTPState;
	    MSRTPStreamOutContext::TContextOutState iCurrentRTCPState;   
	
	private:    
		//friend class CSRTPSession;    
	#ifdef EUNIT_TESTING
        friend class UT_CSRTPStreamOut;        
    #endif                                  
    };

#endif // __SRTP_STREAM_OUT_H__