contentmgmt/referencedrmagent/RefTestAgent/localsdp/inc/sdputil.h
changeset 72 de46a57f75fb
equal deleted inserted replaced
65:970c0057d9bc 72:de46a57f75fb
       
     1 /*
       
     2 * Copyright (c) 2010 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          : SdpUtil.h
       
    16 * Part of       : Local SDP Codec
       
    17 * Interface     : -
       
    18 * Version       : 1.0
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 /**
       
    26  @internalComponent
       
    27 */
       
    28 
       
    29 #ifndef SDPUTIL_H
       
    30 #define SDPUTIL_H
       
    31 
       
    32 //  INCLUDES
       
    33 #include <e32base.h>
       
    34 #include <stringpool.h>
       
    35 #include <e32std.h>
       
    36 #include "_sdpdefs.h"
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 class RReadStream;
       
    40 class RWriteStream;
       
    41 class CSdpConnectionField;
       
    42 class CSSdpKeyField;
       
    43 class CSdpOriginField;
       
    44 class TInetAddr;
       
    45 
       
    46 // CLASS DECLARATION
       
    47 /**
       
    48  *	Common utilities used in the implementation of the Local SDP codec.
       
    49  *  Utility class, cannot be instantiated
       
    50  */
       
    51 class SdpUtil
       
    52 	{
       
    53 
       
    54     public: // New functions
       
    55 
       
    56         /**
       
    57          *  Generic method that checks that all aValue's chars are not on illegal charset
       
    58          *
       
    59          *  @param aIllegalChars Illegal character set
       
    60          *  @param aValue String to be checked
       
    61          *  @param aStart Start position of the string
       
    62          *  @param aEnd End position of the string
       
    63          *  @return Validity of the string
       
    64          */
       
    65 		static TBool IsValidCharSet( 
       
    66             const TDesC8& aIllegalChars, const TDesC8& aValue, TInt aStart, TInt aEnd );
       
    67 
       
    68         /**
       
    69          *  Checks that token list is valid (tokens with space as delimiter)
       
    70          *
       
    71          *  @param aValue String containing tokens
       
    72          *  @return Validity of the string
       
    73          */
       
    74 		static TBool IsTokenList( const TDesC8& aValue );
       
    75 
       
    76         /**
       
    77          *  Checks that the token is valid (substring inside string)
       
    78          *
       
    79          *  @param aValue String containing the token
       
    80          *  @param aStart Start position of the token inside the string
       
    81          *  @param aEnd End position of the token inside the string
       
    82          *  @return Validity of the token
       
    83          */
       
    84 		static TBool IsToken( const TDesC8& aValue, TInt aStart, TInt aEnd );
       
    85 
       
    86         /**
       
    87          *  Checks that the token is valid
       
    88          *
       
    89          *  @param aValue Token string 
       
    90          *  @return Validity of the token
       
    91          */
       
    92 		static TBool IsToken( const TDesC8& aValue );
       
    93 
       
    94         /**
       
    95          *  Checks that the byte string is valid (substring inside string)
       
    96          *
       
    97          *  @param aValue String 
       
    98          *  @param aStart Start position of the byte string inside the string
       
    99          *  @param aEnd End position of the byte string inside the string
       
   100          *  @return Validity of the byte string
       
   101          */
       
   102 		static TBool IsByteString( const TDesC8& aValue, TInt aStart, TInt aEnd );
       
   103 
       
   104         /**
       
   105          *  Checks that the byte string is valid
       
   106          *
       
   107          *  @param aValue String containing the token        
       
   108          *  @return Validity of the byte string
       
   109          */
       
   110 		static TBool IsByteString( const TDesC8& aValue );
       
   111 
       
   112         /**
       
   113          *  Checks that the substring is a token-byte string pair with colon char
       
   114          *  as delimiter of the two strings
       
   115          *
       
   116          *  @param aValue String containing the pair
       
   117          *  @param aStart Start position of the string pair
       
   118          *  @param aEnd End position of the string pair        
       
   119          *  @return Validity of the pair
       
   120          */
       
   121 		static TBool IsTokenTextPair( 
       
   122             const TDesC8& aValue, TInt aStart, TInt aEnd );
       
   123 
       
   124         /**
       
   125          *  Checks that the string conatins valid token-byte string pair with color
       
   126          *  char as delimiter of the two strings
       
   127          *
       
   128          *  @param aValue String containing the pair        
       
   129          *  @return Validity of the byte string
       
   130          */
       
   131 		static TBool IsTokenTextPair( const TDesC8& aValue );
       
   132 
       
   133         /**
       
   134          *  Checks that the string does not contain any whitespace characters
       
   135          *
       
   136          *  @param aValue String        
       
   137          *  @return Validity of the string
       
   138          */
       
   139 		static TBool IsNonWhitespace( const TDesC8& aValue );
       
   140 
       
   141         /**
       
   142          *  Checks that the string contains a valid NTP-time element
       
   143          *
       
   144          *  @param aValue String
       
   145          *  @return Validity of the string
       
   146          */
       
   147 		static TBool IsValidNtpTime( const TDesC8& aValue );
       
   148 
       
   149         /**
       
   150          *  Divides the buffer into a number of lines. Each line is marked
       
   151          *  as a TPtrC8 object and added to array that is returned to the user
       
   152          *  NOTE! Each line in the returned array ends in LF character
       
   153          *  NOTE! The aLines must end in LF character, not '\0' character
       
   154          *
       
   155          *  @param aLines Buffer that contains all the string
       
   156          *  @param aErrCode Error code that is used on leave situations, when the
       
   157          *                  aLines parameter contains invalid string set
       
   158          *  @return Array that contains the division of buffer to lines
       
   159          */
       
   160         static RArray<TPtrC8> DivideToLinesL( 
       
   161             const TDesC8& aLines, TInt aErrCode );
       
   162 
       
   163         /**
       
   164          *  Parses elements from each line. The first item in the returned array
       
   165          *  is the field attribute and equal character (e.g. "a=", "c="), following
       
   166          *  elements are parsed from the string using space character as delimiter
       
   167          *
       
   168          *  @param aLine String containing line that ends to LF character
       
   169          *  @param aErrCode Error code that is used on leave situations, when
       
   170          *                  the contents of aLine are illegal
       
   171          *  @return Array that contains the division of string to elements
       
   172          */
       
   173         static RArray<TPtrC8> GetElementsFromLineL( 
       
   174             const TDesC8& aLine, TInt aErrCode );
       
   175     
       
   176         /**
       
   177          *  Parses elements from each line. The first item in the returned array
       
   178          *  is the field attribute and equal character (e.g. "a=", "c="), following
       
   179          *  elements are parsed from the string using aDelimiter as delimiter
       
   180          *
       
   181          *  @param aLine String containing line that ends to LF character
       
   182          *  @param aDelimiter Delimiter character
       
   183          *  @param aErrCode Error code that is used on leave situations, when
       
   184          *                  the contents of aLine are illegal
       
   185          *  @return Array that contains the division of string to elements
       
   186          */
       
   187         static RArray<TPtrC8> GetElementsFromLineL( 
       
   188             const TDesC8& aLine, TChar aDelimiter, TInt aErrCode ); 
       
   189             
       
   190         /**
       
   191          *  Parses elements from each line. The first item in the returned array
       
   192          *  is the field attribute and equal character (e.g. "a=", "c="), following
       
   193          *  elements are parsed from the string using space character as delimiter
       
   194          *
       
   195          *  @param aLexer Lexer that has been initialized with the string
       
   196          *  @param aErrCode Error code that is used on leave situations, when
       
   197          *                  the contents of aLine are illegal
       
   198          *  @return Array that contains the division of string to elements
       
   199          */       
       
   200         static RArray<TPtrC8> GetElementsFromLineL( 
       
   201             TLex8& aLexer, TChar aDelimiter, TInt aErrCode );
       
   202         
       
   203         /**
       
   204          *  Checks if the string contains only POS-DIGIT characters
       
   205          *
       
   206          *  @param aDes String
       
   207          *  @return Validity of POS-DIGIT string
       
   208          */
       
   209         static TBool IsPosDigit( const TDesC8& aDes );
       
   210 
       
   211         /**
       
   212          *  Checks if the string contains only DIGIT characters
       
   213          *
       
   214          *  @param aDes String
       
   215          *  @return Validity of DIGIT string
       
   216          */
       
   217         static TBool IsDigit( const TDesC8& aDes );
       
   218 
       
   219         /**
       
   220          *  Checks if the string contains valid characters
       
   221          *  
       
   222          *  @param aValidChars Valid characters allowed in the string
       
   223          *  @param aDes String
       
   224          *  @return Validity of the string
       
   225          */
       
   226         static TBool IsValidChars( const TDesC8& aValidChars, const TDesC8& aDes );                
       
   227 
       
   228         /**
       
   229          *  Checks if the string contains only token characters
       
   230          *
       
   231          *  @param aValue String
       
   232          *  @return Validity of the string
       
   233          */
       
   234         static TBool IsTokenChar( const TDesC8& aValue );
       
   235 
       
   236         /**
       
   237          *  Checks if the character is a valid token character
       
   238          *
       
   239          *  @param aChar Character
       
   240          *  @return Validity of the character
       
   241          */
       
   242 		static TBool IsTokenChar( TChar aChar );
       
   243 
       
   244         /**
       
   245          *  Checks if the string is a valid token. The string can contain slash character,
       
   246          *  which divides the line into two tokens. The two tokens are then individually
       
   247          *  verified.
       
   248          *
       
   249          *  @param aValue String
       
   250          *  @return Validity of the string
       
   251          */
       
   252 		static TBool IsTokenCharWithOptionalSlash( const TDesC8& aValue );
       
   253 
       
   254         /**
       
   255          *  Checks if the string is a valid token. The string can contain space characters,
       
   256          *  which divides the string into a number of tokens. Each token is then individually
       
   257          *  verified.
       
   258          *
       
   259          *  @param aValue String
       
   260          *  @return Validity of the string
       
   261          */
       
   262 		static TBool IsTokenCharWithSpacesL( const TDesC8& aValue );
       
   263 
       
   264         /**
       
   265          *  Checks if the string is a valid token. The string can contain slash character,
       
   266          *  which divides the line into two tokens. The two tokens are then individually
       
   267          *  verified.
       
   268          *
       
   269          *  @param aValue String
       
   270          *  @return Validity of the string
       
   271          */
       
   272 		static void EncodeBufferL( 
       
   273             const TDesC8& aValue, TInt aIndex, RWriteStream& aStream );
       
   274 
       
   275         /**
       
   276          *  Sets default network type ("IN") and default address type ("IP4" or "IP6")
       
   277          *  to variables given as parameters
       
   278          *  
       
   279          *  @param aPool String pool
       
   280          *  @param aInetAddr Internet address
       
   281          *  @param aNetType Network type
       
   282          *  @param aAddressType Address type
       
   283          */
       
   284         static void SetDefaultNetTypeAndAddrType( 
       
   285             RStringPool aPool, const TInetAddr& aAddress,
       
   286             RStringF& aNetType, RStringF& aAddressType );
       
   287 
       
   288         /**
       
   289          * Skips spaces until next line break, if the line break can be found.
       
   290          * @param aLexer
       
   291          * @return ETrue if the line break was found, otherwise EFalse. 
       
   292          */
       
   293         static TBool SkipSpacesUntilNextLineBreak( TLex8& aLexer );
       
   294  
       
   295     private:
       
   296 
       
   297         /**
       
   298          *  After the field tag has been parsed out, all the field elements are
       
   299          *  parsed in this method
       
   300          *
       
   301          *  @param aArray Reference to the array that contains the chopped elements
       
   302          *  @param aLexer Used lexer
       
   303          *  @param aDelimiter Delimiter character that determines the separation of elements
       
   304          *  @param aErrCode The error code that is used on leaves, when the argument is invalid
       
   305          */
       
   306         static void ChopElementsFromLineL( 
       
   307             RArray<TPtrC8>& aArray, TLex8& aLexer, TChar aDelimiter, TInt aErrCode );
       
   308         
       
   309         /**
       
   310          *  Private constructor         
       
   311          *  This class can never be instantiated
       
   312          */
       
   313         SdpUtil();
       
   314 	};
       
   315 
       
   316 #endif