realtimenetprots/sipfw/SDP/api/SdpAttributeField.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2003-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          : SdpAttributeField.h
       
    16 * Part of       : SDP Codec
       
    17 * Interface     : SDK API, SDP Codec API
       
    18 * Version       : 1.0
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 #ifndef CSDPATTRIBUTEFIELD_H
       
    25 #define CSDPATTRIBUTEFIELD_H
       
    26 
       
    27 //  INCLUDES
       
    28 #include <e32base.h>
       
    29 #include <stringpool.h>
       
    30 #include "sdpcodecstringconstants.h"
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class RReadStream;
       
    34 class RWriteStream;
       
    35 class CSdpFmtAttributeField;
       
    36 class CSdpAttributeFieldPtrs;
       
    37 
       
    38 // CLASS DECLARATION
       
    39 /**
       
    40  *  @publishedAll
       
    41  *  @released
       
    42  *
       
    43  *	This class encapsulates the attribute field of Session Description Protocol
       
    44  *	for media and session level attributes. Media format/payload type level
       
    45  *  attributes are supported by the CSdpFmtAttributeField class. 
       
    46  * 
       
    47  *	The normative reference for correct formatting and values is
       
    48  *	draft-ietf-mmusic-sdp-new-14 unless specified otherwise in
       
    49  *  member documentation. The implementation supports this normative
       
    50  *  reference, but does not enforce it fully. 
       
    51  *
       
    52  *  @lib sdpcodec.lib
       
    53  */
       
    54 class CSdpAttributeField : public CBase
       
    55 	{
       
    56     public:     // Constructors and destructor
       
    57 
       
    58         /**
       
    59          *	Constructs a new attribute field.
       
    60 		 *			 
       
    61          *	@param aText A string containing a correctly 
       
    62          *         formatted field value terminated by a CRLF.
       
    63          *	@return a new instance.
       
    64          */
       
    65 		IMPORT_C static CSdpAttributeField* DecodeL( const TDesC8& aText );
       
    66 
       
    67         /**
       
    68          *	Constructs a new attribute field and adds the pointer to the 
       
    69          *  cleanup stack.
       
    70 		 *		 
       
    71          *	@param aTest A string containing a correctly 
       
    72          *         formatted field value terminated by a CRLF.
       
    73          *	@return a new instance.
       
    74          */
       
    75 		IMPORT_C static CSdpAttributeField* DecodeLC( const TDesC8& aText );
       
    76 
       
    77         /**
       
    78          *	Constructs a new attribute field. 
       
    79 		 *
       
    80          *	@param aAttribute The attribute name. It can be a pre-
       
    81          *         defined name in the SDP string pool or defined by the 
       
    82          *         client.
       
    83          *	@param aValue A valid attribute value or an empty 
       
    84          *         descriptor to omit the value part.
       
    85          *	@return a new instance.
       
    86 		 */
       
    87 		IMPORT_C static CSdpAttributeField* NewL(
       
    88             RStringF aAttribute, const TDesC8& aValue );
       
    89 
       
    90         /**
       
    91          *	Constructs a new attribute field and adds the pointer to the 
       
    92          *  cleanup stack. 
       
    93 		 *
       
    94          *	@param aAttribute The attribute name. It can be a pre-defined 
       
    95          *         name in the SDP string pool or defined by the client.
       
    96          *	@param aValue A valid attribute value or an empty 
       
    97          *         descriptor to omit the value part.
       
    98          *	@return a new instance.
       
    99 		 */
       
   100 		IMPORT_C static CSdpAttributeField* NewLC(
       
   101             RStringF aAttribute, const TDesC8& aValue );
       
   102 
       
   103  		/**
       
   104 		 *	Deletes the resources held by the instance.
       
   105 		 */
       
   106 		IMPORT_C ~CSdpAttributeField();
       
   107 
       
   108     public:     // New functions
       
   109 	
       
   110     	/**
       
   111 		 *	Outputs the field formatted according to SDP syntax and including
       
   112 		 *  the terminating CRLF.
       
   113 		 * 
       
   114 		 *	@param aStream Stream used for output. On return the 
       
   115          *         stream includes correctly formatted attribute field.
       
   116 		 */
       
   117 		IMPORT_C void EncodeL( RWriteStream& aStream ) const;
       
   118 
       
   119 		/**
       
   120 		 *	Creates a new instance that is equal to the target.
       
   121 		 *
       
   122 		 *	@return a new instance.
       
   123 		 */
       
   124 		IMPORT_C CSdpAttributeField* CloneL() const;
       
   125 
       
   126 		/**	
       
   127 		 *	Compares this instance to another for equality.
       
   128 		 *
       
   129 		 *	@param aObj: The instance to compare to.
       
   130 		 *	@return ETrue if equal, EFalse if not.
       
   131 		 */
       
   132 		IMPORT_C TBool operator == ( const CSdpAttributeField& aObj ) const;
       
   133 
       
   134 		/**
       
   135 		 *	Gets the attribute name.
       
   136 		 *	
       
   137 		 *	@return	The attribute name. The name can be pre-defined 
       
   138          *          name in the SDP string table or defined by the client.
       
   139 		 */
       
   140 		IMPORT_C RStringF Attribute() const;
       
   141 
       
   142 		/**
       
   143 		 *	Gets the attribute.
       
   144 		 *
       
   145  		 *	@return	The value or an empty descriptor if there is no value part.
       
   146 		 */
       
   147 		IMPORT_C const TDesC8& Value() const;
       
   148 
       
   149 		/**
       
   150 		 *	Sets the attribute and attribute value.
       
   151 		 *
       
   152          *	@param aAttribute A valid attribute name. It can be a 
       
   153          *         pre-defined name in the SDP string pool or 
       
   154          *         defined by the client.
       
   155          *	@param aValue A valid attribute value or an empty 
       
   156          *         descriptor to omit the value part.
       
   157 		 *  @leave KErrSdpCodecAttributeField if the attribute part is not 
       
   158 		 *         pre-defined EAttributeFmtp or EAttributeRtpmap.
       
   159 		 */
       
   160 		IMPORT_C void SetL( RStringF aAttribute, const TDesC8& aValue );
       
   161 		
       
   162 		/**
       
   163  		 *	Assigns attribute to the format level attribute.
       
   164  		 *  In the final output the attribute will placed after format level
       
   165 		 *  attribute.
       
   166  		 *
       
   167  		 *	@param aFmtAttribute A format level 
       
   168  		 *         attribute this attribute is assigned to.
       
   169  		 */
       
   170  		IMPORT_C void AssignTo(const CSdpFmtAttributeField& aFmtAttribute);
       
   171 		
       
   172 		/**
       
   173 		 *	Test if the attribute belongs to the given format level attribute.
       
   174 		 *  Note, that the check can be true for the media level paremeter if
       
   175 		 *  it appears after the last format level attribute.
       
   176 		 *
       
   177 		 *	@param  aFmtAttribute: A format level 
       
   178 		 *          attribute this attribute belongs to.
       
   179 		 *	@return	ETrue if attribute belongs to the format level attribute, 
       
   180 		 *          EFalse otherwise.
       
   181 		 */
       
   182 		IMPORT_C TBool BelongsTo(const CSdpFmtAttributeField& aFmtAttribute) const;
       
   183 
       
   184     public:     // Internal to codec
       
   185 
       
   186         /**
       
   187          *  Externalizes the object to stream
       
   188          *
       
   189          *  @param aStream Stream where the object's state will be stored
       
   190          */
       
   191 		void ExternalizeL( RWriteStream& aStream ) const;
       
   192 
       
   193         /**
       
   194          *  Creates object from the stream data
       
   195          *
       
   196          *  @param aStream Stream where the object's state will be read
       
   197          *  @return Initialized object
       
   198          */
       
   199         static CSdpAttributeField* InternalizeL( RReadStream& aStream );
       
   200         
       
   201         /**
       
   202          *  Informs if the attribute belongs to any format level attribute.
       
   203          *
       
   204          *  @return ETrue if attribute belongs to any format level 
       
   205 		 *			attribute, EFalse otherwise.
       
   206          */
       
   207         TBool IsFmtAttribute();
       
   208     
       
   209 	private:    // Constructors
       
   210 
       
   211         /**
       
   212          *  Constructor
       
   213          */
       
   214 		CSdpAttributeField();
       
   215 
       
   216         /**
       
   217          *  Second phase constructor
       
   218          *
       
   219          *  @param aText Text string ending to LF character
       
   220          */
       
   221         void ConstructL( const TDesC8& aText );
       
   222 
       
   223         /**
       
   224          *  Second phase constructor
       
   225          *
       
   226          *  @param aAttribute Attribute identifier
       
   227          *  @param aValue Value of the attribute of KNullDesC8
       
   228          */
       
   229         void ConstructL( RStringF aAttribute, const TDesC8& aValue );
       
   230     
       
   231     private:    // Internal
       
   232 
       
   233         /**
       
   234          *  Verifies that attribute is valid property attribute and initializes
       
   235          *  the member variables of class accordingly
       
   236          *
       
   237          *  @param aAttribute Attribute in descriptor
       
   238          */
       
   239         void FormatProperyAttributeL( const TDesC8& aAttribute );
       
   240 
       
   241         /**
       
   242          *  Verifies that attribute is valid value attribute and initializes
       
   243          *  the member variables of class accordingly
       
   244          *
       
   245          *  @param aArray Array of the attributes
       
   246          */
       
   247         void FormatValueAttributeL( const TDesC8& aAttribute,
       
   248                                     const TDesC8& aValue );
       
   249 
       
   250         /**
       
   251          *  Verifies that the value is valid for the attribute
       
   252          *
       
   253          *  @param aAttribute The attribute
       
   254          *  @param aArray Array containing the values (and attribute)
       
   255          */
       
   256         void VerifyValueAttributeL( SdpCodecStringConstants::TStrings aString,
       
   257                                     const TDesC8& aValue );
       
   258                                     
       
   259         /**
       
   260          *  Forms attribute and value strings out of the token array
       
   261          *  and pushes both (aAttribute & aValue) into cleanup stack
       
   262          *
       
   263          *  @param aArray Token array
       
   264          *  @param aAttribute Attribute string (in cleanup stack)
       
   265          *  @param aValue Value string (in cleanup stack)
       
   266          */
       
   267         void CreateAttributeAndValueStringsLC( RArray<TPtrC8>& aArray,
       
   268                                                HBufC8*& aAttribute,
       
   269                                                HBufC8*& aValue );
       
   270 
       
   271         /**
       
   272          *  Checks if the value is among the valid orient attributes
       
   273          *
       
   274          *  @param aValue Value string
       
   275          */
       
   276         void CheckValidOrientL( const TDesC8& aValue );
       
   277 
       
   278         /**
       
   279          *  Checks if the value is valid language attribute as
       
   280          *  specified in RFC 3066
       
   281          *
       
   282          *  @param aValue Value string
       
   283          */
       
   284         void CheckValidLangStrL( const TDesC8& aValue );
       
   285 
       
   286         /**
       
   287          *  Checks if the value is valid framerate attribute
       
   288          *
       
   289          *  @param aValue Value string
       
   290          */
       
   291         void CheckValidFrameRateL( const TDesC8& aValue );
       
   292         
       
   293         /**
       
   294          *  Checks if the value is among valid uri value for control attribute
       
   295          *
       
   296          *  @param aValue Value string
       
   297          */       
       
   298         void CheckValidControlL( const TDesC8& aValue );
       
   299 
       
   300         /**
       
   301          *  Checks if the value is valid value for group attribute as
       
   302          *  specified in RFC 3388
       
   303          *
       
   304          *  @param aValue Value string
       
   305          */       
       
   306         void CheckValidGroupL( const TDesC8& aValue );
       
   307 
       
   308         /**
       
   309          *  Checks if the value is valid value for des attribute as
       
   310          *  specified in RFC 3312
       
   311          *
       
   312          *  @param aValue Value string
       
   313          */       
       
   314         void CheckValidDesL( const TDesC8& aValue );
       
   315 
       
   316         /**
       
   317          *  Checks if the value is valid value for curr and conf attribute as
       
   318          *  specified in RFC 3312
       
   319          *
       
   320          *  @param aValue Value string
       
   321          */       
       
   322         void CheckValidCurrAndConfL( const TDesC8& aValue );
       
   323 
       
   324         /**
       
   325          *  Checks if value is included in the list of predefined values
       
   326          *
       
   327          *  @param aItemsCount Predefined values count
       
   328          *  @param aValuesList List of predefined values
       
   329          *  @param aValue Value string
       
   330          */       
       
   331         void ValidValueInListL( TInt aItemsCount, 
       
   332                                 const TText8* const aValuesList[], 
       
   333                                 const TDesC8& aValue );
       
   334 
       
   335         /**
       
   336          *  Checks if the value is valid value for range attribute as
       
   337          *  specified in RFC 2326
       
   338          *
       
   339          *  @param aValue Value string
       
   340          */       
       
   341         void CheckValidRangeL( const TDesC8& aValue );
       
   342 
       
   343 
       
   344         /**
       
   345          *  Checks if the value is valid rtpmap string
       
   346          *
       
   347          *  @param aValue Value string
       
   348          */   
       
   349         void CheckValidRtpmapL( const TDesC8& aValue );
       
   350 
       
   351         /**
       
   352          *  Checks if the value is valid fmtp string
       
   353          *
       
   354          *  @param aValue Value string
       
   355          */   
       
   356         void CheckValidFmtpL( const TDesC8& aValue );
       
   357         
       
   358         /**
       
   359          *  Set attribute and values. Attribute is not one of predefined ones.
       
   360          *
       
   361          *  @param aAttribute Attribute string (in cleanup stack)
       
   362          *  @param aValue Value string
       
   363          */   
       
   364         void SetNotPredefinedAttributeL( const TDesC8& aAttribute, 
       
   365                                          const TDesC8& aValue );
       
   366         
       
   367         void CreateAttributeFieldPtrsL();
       
   368         
       
   369         inline CSdpAttributeFieldPtrs& AttributeFieldPtrs();      
       
   370         
       
   371         inline const CSdpAttributeFieldPtrs& AttributeFieldPtrs() const;
       
   372 	   
       
   373 		void __DbgTestInvariant() const;
       
   374 
       
   375 
       
   376     private:    // Data
       
   377 
       
   378         // String pool
       
   379         RStringPool iPool;
       
   380 
       
   381         // Attribute name
       
   382         RStringF iAttribute;
       
   383 
       
   384         // Flag indicating if the attribute is a property attribute
       
   385         TBool iPropertyAttribute;
       
   386 
       
   387         // Value field
       
   388         HBufC8* iValue;
       
   389 	};
       
   390 
       
   391 #endif // CSDPATTRIBUTEFIELD_H