dvrengine/CommonRecordingEngine/inc/CCRRTSPCommand.h
branchRCL_3
changeset 22 826cea16efd9
parent 21 798ee5f1972c
child 23 13a33d82ad98
equal deleted inserted replaced
21:798ee5f1972c 22:826cea16efd9
     1 /*
       
     2 * Copyright (c) 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 the License "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:    Class for parsing and producing a command string*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CCRRTSPCOMMAND_H
       
    21 #define CCRRTSPCOMMAND_H
       
    22 
       
    23 // INCLUDES
       
    24 #include "CRRtspCommon.h"
       
    25 #include <Hash.h>
       
    26 
       
    27 // CONSTANTS
       
    28 // None
       
    29 
       
    30 // MACROS
       
    31 // None
       
    32 
       
    33 // DATA TYPES
       
    34 // None
       
    35 
       
    36 // FORWARD DECLARATIONS
       
    37 // None
       
    38 
       
    39 // CLASS DECLARATION
       
    40 
       
    41 /**
       
    42 *  Class that parses and produces rtsp commands as in rfc2326.
       
    43 *
       
    44 *  @lib CommonRecordingEngine.lib
       
    45 *  @since Series 60 3.0
       
    46 */
       
    47 class CCRRtspCommand : public CCRRtspCommon
       
    48     {
       
    49     
       
    50 public: // Data types 
       
    51 
       
    52     /**
       
    53     * Enum for subset of RTSP commands 
       
    54     */
       
    55     enum TCommand
       
    56         {
       
    57 		ERTSPCommandPLAY = 0,  /**< Command for triggering clip that has been SETUP */
       
    58         ERTSPCommandPAUSE,     /**< Command for pausing a clip that is already  playing */
       
    59         ERTSPCommandTEARDOWN,  /**< Command for quitting a session */
       
    60         ERTSPCommandOPTIONS,   /**< No operation, except ping */
       
    61         ERTSPCommandDESCRIBE,  /**< Command for acquiring an SDP */
       
    62         ERTSPCommandSETUP,     /**< Command for setting up audio or video stream */
       
    63         ERTSPCommandNOCOMMAND  /**< init value, no-operation */
       
    64         };    
       
    65 
       
    66 public: // Constructors and destructor
       
    67 
       
    68     /**
       
    69     * Two-phased constructor.
       
    70     * @return CCRRtspCommand pointer to CCRRtspCommand class.
       
    71     */
       
    72     static CCRRtspCommand* NewL();
       
    73 
       
    74     /**
       
    75     * Destructor.
       
    76     */
       
    77     virtual ~CCRRtspCommand( );
       
    78 
       
    79 public: // New functions
       
    80 
       
    81     /**
       
    82     * Method that is used to give rtsp command to this class.
       
    83     * command is something alike:
       
    84     * "PLAY rtsp://vishnu.wipsl.com/oops/winter_fun.mp4/ RTSP/1.0\r\n..."
       
    85     * @since Series 60 3.0
       
    86     * @param aString is the response string
       
    87     * @return none. 
       
    88     *         May leave with symbian error codes. At least following may be 
       
    89     *         seen: KErrUnderflow if there is \r\n\r\n sequence in the string
       
    90     *         marking end of response or if there is content (like SDP) and the
       
    91     *         content lenght is too short; KErrNotSupported if it doesn't look
       
    92     *         like RTSP at all.
       
    93     */
       
    94     void TryParseL( const TDesC8 &aString );
       
    95 
       
    96     /**
       
    97     * Method for getting URL. 
       
    98     * @since Series 60 3.0
       
    99     * @param aURL is string descriptor allocated by caller that
       
   100     *        will have its content set to block allocated by instance
       
   101     *        of this class containing the session id. 
       
   102     * @return KErrNone if no error, KErrNotFound if URL is not there.
       
   103     */
       
   104     TInt URL( TPtrC8& aURL ); 
       
   105             
       
   106     /**
       
   107     * Method for setting URL.
       
   108     * @since Series 60 3.0
       
   109     * @param aURL is string descriptor allocated by caller. 
       
   110     * @return none.
       
   111     */
       
   112     void SetURL( const TDesC8& aURL ); 
       
   113 
       
   114     /**
       
   115     * Method for setting command.
       
   116     * @since Series 60 3.0
       
   117     * @param aCommand is the command that will be set.
       
   118     * @return none.
       
   119     */
       
   120     void SetCommand( TCommand aCommand  ); 
       
   121     
       
   122     /**
       
   123     * Method for setting authentication info.
       
   124     * @since Series 60 3.0
       
   125     * @param aAuth is ETrue if authentication is to be used.
       
   126     *        When constructing command string, authentication headers
       
   127     *        will be added. See also SetUserNameL et al. 
       
   128     * @return none.
       
   129     */
       
   130     void SetAuthentication( TBool aAuth  ); 
       
   131 
       
   132     /**
       
   133     * Sets identification string to be sent as 'UserAgent' header.
       
   134     * No header is sent if not identification is not set.
       
   135     * @since Series 60 3.0
       
   136     * @param aUserAgent user agent identification.
       
   137     * @return none.
       
   138     */
       
   139     void SetUserAgentL( const TDesC8& aUserAgent );
       
   140 
       
   141     /**
       
   142     * Sets connection bandwidth to be sent as 'Bandwidth' header.
       
   143     * No header is sent if bandwidth is not set.
       
   144     * @since Series 60 3.0
       
   145     * @param aBandwidth connection bandwidth in bit/s.
       
   146     * @return none.
       
   147     */
       
   148     void SetBandwidth( TInt aBandwidth );
       
   149 
       
   150     /**
       
   151     * Sets profile identification for 'x-wap-profile' header.
       
   152     * @since Series 60 3.0
       
   153     * No header is sent if identification is not set.
       
   154     * @param aWapProfile profile identification.
       
   155     * @return none.
       
   156     */
       
   157     void SetWapProfileL( const TDesC8& aWapProfile );
       
   158 
       
   159     /**
       
   160     * Method for getting command.
       
   161     * @since Series 60 3.0
       
   162     * @param none.
       
   163     * @return the command.
       
   164     */
       
   165     CCRRtspCommand::TCommand Command( void ) const; 
       
   166         
       
   167     /**
       
   168     * Method that does opposite of parse: it produces a RTSP command.
       
   169     * @since Series 60 3.0
       
   170     * @param none.
       
   171     * @return string descriptor containing the command
       
   172     */
       
   173     TPtrC8& ProduceL( void ); 
       
   174 
       
   175     /**
       
   176     * Appends string to the buffer.
       
   177     * @since Series 60 3.0
       
   178     * @param aBuffer a buffer where to add text.
       
   179     * @param aTxt a string to append.
       
   180     * @return none.
       
   181     */
       
   182     void AppendL( HBufC8*& aBuffer,
       
   183                   const TDesC8& aTxt );
       
   184 
       
   185     /**
       
   186     * Appends integer value as text to the buffer.
       
   187     * @since Series 60 3.0
       
   188     * @param aBuffer a buffer where to add text.
       
   189     * @param aNum a numerical value to append.
       
   190     * @return none.
       
   191     */
       
   192     void AppendNumL( HBufC8*& aBuffer,
       
   193                      const TInt aNum );
       
   194 
       
   195     /**
       
   196     * Appends formatted text to the buffer.
       
   197     * @since Series 60 3.0
       
   198     * @param aBuffer a buffer where to add text.
       
   199     * @param aFmt a format string to use.
       
   200     * @return none.
       
   201     */
       
   202     void AppendFormatL( HBufC8*& aBuffer,
       
   203                         TRefByValue<const TDesC8> aFmt, ... );
       
   204 
       
   205 private: // Constructors and destructors
       
   206 
       
   207     /**
       
   208      * default constructor
       
   209      */
       
   210      CCRRtspCommand(); 
       
   211      
       
   212     /** 
       
   213      * 2nd phase constructor 
       
   214      */
       
   215      void ConstructL();
       
   216     
       
   217 private: // new methods:
       
   218 
       
   219     /** 
       
   220     * Method for finding the URL this command is about
       
   221     * @since Series 60 3.0
       
   222     * @param none.
       
   223     * @return none but will leave with KErrNotSupported 
       
   224     *         if it doesn't look like RTSP
       
   225     */
       
   226     void FindURLL( void ); 
       
   227 
       
   228     /**
       
   229     * Generates authentication header iAuthHeader using given values.
       
   230     * Method described in RFC 2069 "An Extension to HTTP : Digest Access 
       
   231     * Authentication".
       
   232     * @since Series 60 3.0
       
   233     * @param aMethod Method name (e.g. "DESCRIBE" / "SETUP" / etc.)
       
   234     */
       
   235     void CalculateDigestResponseL( const TDesC8& aMethod ); 
       
   236     
       
   237     /**
       
   238     * Generates authentication header iAuthHeader using given values.
       
   239     * Method described in RFC 2617 "HTTP Authentication: Basic and Digest 
       
   240     * Access Authentication".
       
   241     * @since Series 60 3.0
       
   242     * @param aMethod Method name (e.g. "DESCRIBE" / "SETUP" / etc.)
       
   243     */
       
   244     void CalculateBasicResponseL( const TDesC8& aMethod );
       
   245     
       
   246     /**
       
   247     * Calculates MD5 hash of the message.
       
   248     * @since Series 60 3.0
       
   249     * @param aMessage Message.
       
   250     * @param aHash On return, contains message hash.
       
   251     */
       
   252     void HashL( const TDesC8& aMessage, TDes8& aHash );  
       
   253        
       
   254 private: // Data
       
   255 
       
   256     /** 
       
   257     * What command this is.
       
   258     */
       
   259     TCommand iCommand; 
       
   260     
       
   261     /**
       
   262     * What is the URL that this command is about.
       
   263     */
       
   264     TPtrC8 iURL; 
       
   265     
       
   266     /**
       
   267     * String descriptor that we retur with ProduceL.
       
   268     */
       
   269     TPtrC8 iProductDescriptor; 
       
   270     
       
   271     /**
       
   272     * Authentication header.
       
   273     */
       
   274     HBufC8* iAuthHeader;
       
   275         
       
   276     /**
       
   277     * MD5 message digest class. Required for HTTP digest authentication.
       
   278     */
       
   279     CMD5* iMD5Calculator;
       
   280     
       
   281     /**
       
   282     * If authentication is needed.
       
   283     */
       
   284     TBool iAuthenticationNeeded;
       
   285 
       
   286     /**
       
   287     * User Agent header if present.
       
   288     */
       
   289     HBufC8* iUserAgent;
       
   290 
       
   291     /**
       
   292     * Connection bandwidth in bit/s for 'Bandwidth' header.
       
   293     */
       
   294     TInt iBandwidth;
       
   295 
       
   296     /**
       
   297     * Bandwidth present.
       
   298     */
       
   299     TBool iBandwidthAvailable;
       
   300 
       
   301     /**
       
   302     * x-wap-profile if present.
       
   303     */
       
   304     HBufC8* iWapProfile;
       
   305     
       
   306     };
       
   307 
       
   308 #endif // CCRRTSPCOMMAND_H
       
   309 
       
   310 // End of file