contentmgmt/referencedrmagent/RefTestAgent/localsdp/api/sdporiginfield.h
changeset 66 8873e6835f7b
equal deleted inserted replaced
62:b23410e29e22 66:8873e6835f7b
       
     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          : SdpOriginField.h
       
    16 * Part of       : Local SDP Codec
       
    17 * Interface     : SDK API, Local SDP Codec API
       
    18 * Version       : 1.0
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 #ifndef CSDPORIGINFIELD_H
       
    25 #define CSDPORIGINFIELD_H
       
    26 
       
    27 //  INCLUDES
       
    28 #include <e32base.h>
       
    29 #include <in_sock.h>
       
    30 #include <stringpool.h>
       
    31 #include "_sdpdefs.h"
       
    32 
       
    33 //  CONSTANTS
       
    34 const TInt KMaxAddressLength = 256;
       
    35 
       
    36 //  FORWARD DECLARATIONS
       
    37 class RReadStream;
       
    38 class RWriteStream;
       
    39 class CSdpOriginFieldPtrs;
       
    40 
       
    41 // CLASS DECLARATION
       
    42 /**
       
    43  *  @publishedAll
       
    44  *  @released
       
    45  *
       
    46  *	This class encapsulates the origin field of 
       
    47  *  the Session Description Protocol.
       
    48  * 
       
    49  *	The normative reference for correct formatting and values is
       
    50  *	draft-ietf-mmusic-sdp-new-14 unless specified otherwise in
       
    51  *  member documentation. The implementation supports this normative
       
    52  *  reference, but does not enforce it fully. 
       
    53  *
       
    54  *  @lib localsdpcodec.lib
       
    55  */
       
    56 class CSdpOriginField : public CBase
       
    57 	{
       
    58     public:     // Constructors and destructor
       
    59 
       
    60         /**
       
    61          *	Constructs a new origin field.
       
    62 		 *		 
       
    63          *	@param aText A string containing a correctly 
       
    64          *         formatted field value terminated by a CRLF.
       
    65          *	@return a new instance.
       
    66          */
       
    67 		IMPORT_C static	CSdpOriginField* DecodeL( const TDesC8& aText );
       
    68 
       
    69         /**
       
    70          *	Constructs a new origin field and adds the pointer to the cleanup 
       
    71          *  stack.
       
    72 		 * 		
       
    73          *	@param aText A string containing a correctly 
       
    74          *         formatted field value terminated by a CRLF.
       
    75          *	@return a new instance.
       
    76          */
       
    77 		IMPORT_C static	CSdpOriginField* DecodeLC( const TDesC8& aText );
       
    78 
       
    79         /**
       
    80          *	Constructs a new origin field.
       
    81 		 *	         
       
    82          *	@param aUserName A valid user name value.
       
    83          *	@param aSessionId A valid session id value.
       
    84          *	@param aSessionVersion A valid announcement version value.
       
    85          *	@param aAddress A unicast IP address from either
       
    86 		 *         KAfInet or KAfInet6 family.
       
    87          *	@return a new instance.
       
    88          */
       
    89 		IMPORT_C static	CSdpOriginField* NewL( const TDesC8& aUserName, 
       
    90 											   TInt64 aSessionId, 
       
    91 											   TInt64 aSessionVersion, 
       
    92 											   TInetAddr& aAddress );
       
    93 
       
    94         /**
       
    95          *	Constructs a new origin field and adds the pointer to the cleanup 
       
    96          *  stack.
       
    97 		 *	         
       
    98          *	@param aUserName A valid user name value.
       
    99          *	@param aSessionId A valid session id value.
       
   100          *	@param aSessionVersion A valid announcement version value.
       
   101          *	@param aAddress A unicast IP address from either
       
   102 		 *         KAfInet or KAfInet6 family.
       
   103          *	@return a new instance.
       
   104          */
       
   105 		IMPORT_C static	CSdpOriginField* NewLC( const TDesC8& aUserName, 
       
   106 											    TInt64 aSessionId, 
       
   107 											    TInt64 aSessionVersion, 
       
   108 											    TInetAddr& aAddress );
       
   109 
       
   110 		/**
       
   111          *	Constructs a new origin field.
       
   112 		 *	
       
   113          *	@param aUserName A valid user name value.
       
   114          *	@param aSessionId A valid session id value.
       
   115          *	@param aSessionVersion A valid announcement version value.
       
   116          *	@param aNetType A valid network type value (typically "IN").
       
   117 		 *  @param aAddressType A valid address type value 
       
   118 		 *         (typically "IP4" or "IP6").
       
   119 		 *	@param aAddress A unicast IP Address, Fully 
       
   120          *         Qualified Domain Name (FQDN), or an other type of 
       
   121          *         address allowed for the address type.
       
   122          *	@return a new instance.
       
   123          */
       
   124 		IMPORT_C static	CSdpOriginField* NewL( const TDesC8& aUserName, 
       
   125 											TInt64 aSessionId, 
       
   126 											TInt64 aSessionVersion, 
       
   127 											RStringF aNetType, 
       
   128 											RStringF aAddressType, 
       
   129 											const TDesC8& aAddress );
       
   130 
       
   131 		/**
       
   132          *	Constructs a new origin field and adds the pointer to the cleanup 
       
   133          *  stack.
       
   134 		 *	
       
   135          *	@param aUserName A valid user name value.
       
   136          *	@param aSessionId A valid session id value.
       
   137          *	@param aSessionVersion A valid announcement version value.
       
   138          *	@param aNetType A valid network type value (typically "IN").
       
   139 		 *  @param aAddressType A valid address type value 
       
   140 		 *         (typically "IP4" or "IP6").
       
   141 		 *	@param aAddress A unicast IP Address, Fully Qualified Domain
       
   142 		 *         Name (FQDN), or an other type of address allowed
       
   143 		 *         for the address type.
       
   144          *	@return a new instance.
       
   145          */
       
   146 		IMPORT_C static	CSdpOriginField* NewLC( const TDesC8& aUserName, 
       
   147 											TInt64 aSessionId, 
       
   148 											TInt64 aSessionVersion, 
       
   149 											RStringF aNetType, 
       
   150 											RStringF aAddressType, 
       
   151 											const TDesC8& aAddress );
       
   152 
       
   153 		/**
       
   154 		 *	Deletes the resources held by the instance.
       
   155 		 */
       
   156 		IMPORT_C ~CSdpOriginField();
       
   157 
       
   158     public: // New functions
       
   159 
       
   160 		/**
       
   161 		 *	Outputs the field formatted according to SDP syntax and including
       
   162 		 *  the terminating CRLF.
       
   163 		 * 
       
   164 		 *	@param aStream Stream used for output. On return 
       
   165          *         the stream includes correctly formatted origin field.
       
   166 		 */
       
   167 		IMPORT_C void EncodeL( RWriteStream& aStream ) const;
       
   168 
       
   169 		/**
       
   170     	 *	Creates a new instance that is equal to the target.
       
   171 		 *
       
   172 		 *	@return a new instance.
       
   173 		 */
       
   174 		IMPORT_C CSdpOriginField* CloneL() const;
       
   175 
       
   176 		/**	
       
   177 		 *	Compares this instance to another for equality.
       
   178 		 *
       
   179 		 *	@param aObj The instance to compare to.
       
   180 		 *	@return ETrue if equal, EFalse if not.
       
   181 		 */
       
   182 		IMPORT_C TBool operator == ( const CSdpOriginField& aObj ) const;
       
   183 
       
   184 		/**
       
   185 		 *	Gets the user name.
       
   186 		 *
       
   187 		 *	@return User name.
       
   188 		 */
       
   189 		IMPORT_C const TDesC8& UserName() const;
       
   190 
       
   191 		/**
       
   192 		 *	Sets the user name.
       
   193 		 *
       
   194 		 *	@param aValue A valid user name value.
       
   195 		 *	@leave KErrSdpCodecOriginField if aValue is not a valid user name.
       
   196 		 */
       
   197 		IMPORT_C void SetUserNameL( const TDesC8& aValue );
       
   198 
       
   199 		/**
       
   200 		 *	Gets the session id of the origin field.
       
   201 		 *  
       
   202 		 *	@return Session id.
       
   203 		 */
       
   204 		IMPORT_C TInt64 SessionId() const;
       
   205 
       
   206 		/**
       
   207 		 *	Sets the session id.
       
   208 		 *
       
   209 		 *	@param aValue A valid session id value.
       
   210 		 */
       
   211 		IMPORT_C void SetSessionId( TInt64 aValue );
       
   212 		
       
   213 		/**
       
   214 		 *	Gets the announcement version.
       
   215 		 *	
       
   216 		 *	@return Version.
       
   217 		 */
       
   218 		IMPORT_C TInt64 Version() const;
       
   219 
       
   220 		/**
       
   221 		 *	Sets the announcement version..
       
   222 		 *
       
   223 		 *	@param aValue A valid version value.
       
   224 		 */
       
   225 		IMPORT_C void SetVersion( TInt64 aValue );
       
   226 
       
   227 		/**
       
   228 		 *	Gets the network type.
       
   229 		 *
       
   230 		 *	@return The network type from pre-defined SDP string 
       
   231          *          table or given by the user.
       
   232 		 */
       
   233 		IMPORT_C RStringF NetType() const;
       
   234 
       
   235 		/**
       
   236 		 *	Gets the address type.
       
   237 		 *
       
   238 		 *	@return The address type from pre-defined SDP string 
       
   239          *          table or given by the user.
       
   240 		 */
       
   241 		IMPORT_C RStringF AddressType() const;
       
   242 		
       
   243 		/**
       
   244 		 *	Gets the address.
       
   245 		 *
       
   246 		 *	@return Address as an IP address or null if it is
       
   247 		 *          not an IP address. This may be e.g. when the address has 
       
   248 		 *          been specified as a FQDN. In this case, the address can be 
       
   249 		 *          accessed using the other getters.
       
   250 		 */
       
   251 		IMPORT_C const TInetAddr* InetAddress() const;
       
   252 
       
   253 		/**
       
   254 		 *	Gets the address.
       
   255 		 *
       
   256 		 *  @return Address as a string.
       
   257 		 */
       
   258 		IMPORT_C const TDesC8& Address() const;
       
   259 
       
   260 		/**
       
   261 		 *	Sets the address, network and address type.
       
   262 		 *	Also sets the network type to "IN" and address type to "IP4" or 
       
   263 		 *  "IP6" depending on the address family of aValue.
       
   264 		 *
       
   265          *	@param aValue A unicast IP address from either KAfInet 
       
   266          *         or KAfInet6 family.
       
   267 		 */
       
   268 		IMPORT_C void SetInetAddress( const TInetAddr& aValue );
       
   269 
       
   270 		/**
       
   271 		 *	Sets the address, network and address type.
       
   272 		 *
       
   273 		 *	@param aAddress A unicast IP Address, Fully Qualified Domain
       
   274 		 *         Name (FQDN), or an other type of address allowed for the
       
   275 		 *         address type.
       
   276          *	@param aNetType A valid network type value (typically "IN").
       
   277 		 *  @param aAddressType A valid address type value 
       
   278 		 *         (typically "IP4" or "IP6").
       
   279 		 *	@leave KErrSdpCodecOriginField if aNetType or aAddressType are not
       
   280 		 *		   valid tokens, or aAddress is invalid, or aAddress type 
       
   281 		 *		   is not aligned with the address format
       
   282 		 */
       
   283 		IMPORT_C void SetAddressL( const TDesC8& aAddress, 
       
   284 								   RStringF aNetType, 
       
   285 								   RStringF aAddressType );
       
   286         
       
   287     public:     // Internal to codec
       
   288 
       
   289         /**
       
   290          *  Externalizes the object to stream
       
   291          *
       
   292          *  @param aStream Stream where the object's state will be stored
       
   293          */
       
   294 		void ExternalizeL( RWriteStream& aStream ) const;
       
   295 
       
   296         /**
       
   297          *  Creates object from the stream data
       
   298          *
       
   299          *  @param aStream Stream where the object's state will be read	
       
   300          *  @return Initialized object
       
   301          */
       
   302 		static CSdpOriginField* InternalizeL( RReadStream& aStream );
       
   303 
       
   304 	private:    // Constructors
       
   305 
       
   306         /**
       
   307          *  Constructor
       
   308          */
       
   309 		CSdpOriginField();
       
   310 
       
   311         /**
       
   312          *  Second phase constructor. Parses the text string and initializes
       
   313          *  the member variables
       
   314          *         
       
   315          *  @param aText Line of text that will be parsed (ends on the newline)
       
   316          */
       
   317 		void ConstructL( const TDesC8& aText );
       
   318         
       
   319         /**
       
   320          *  Second phase constructor. Constructs the object.
       
   321          *
       
   322          *  @param aUserName  A valid user name value.
       
   323          *  @param aSessionId A valid session id value.
       
   324          *  @param aSessionVersion A valid announcement version value.
       
   325          *  @param aAddress A unicast IP address from either
       
   326 		 *                  KAfInet or KAfInet6 family.        
       
   327          */
       
   328 		void ConstructL( const TDesC8& aUserName, 
       
   329 						 TInt64 aSessionId, 
       
   330                          TInt64 aSessionVersion, 
       
   331 						 TInetAddr& aUnicastAddress );
       
   332          
       
   333         /**                        
       
   334          *	Second phase constructor. Constructs the object.
       
   335 		 *	
       
   336          *	@param aUserName  A valid user name value.
       
   337          *	@param aSessionId A valid session id value.
       
   338          *	@param aSessionVersion A valid announcement version value.
       
   339          *	@param aNetType A valid network type value (typically "IN").
       
   340 		 *  @param aAddressType A valid address type value 
       
   341 		 *         (typically "IP4" or "IP6").
       
   342 		 *	@param aAddress A unicast IP Address, Fully Qualified Domain
       
   343 		 *         Name (FQDN), or an other type of address allowed
       
   344 		 *         for the address type.
       
   345          */
       
   346         void ConstructL( const TDesC8& aUserName, 
       
   347 	                     TInt64 aSessionId, 
       
   348 	                     TInt64 aSessionVersion, 
       
   349 	                     RStringF aNetType, 
       
   350 					     RStringF aAddressType, 
       
   351 	                     const TDesC8& aAddress );
       
   352 
       
   353         // These are unnecessary? Derived from CBase, prevents the use
       
   354 		CSdpOriginField( const CSdpOriginField& ); // Hidden.
       
   355 		CSdpOriginField& operator = ( const CSdpOriginField& ); // Hidden
       
   356 
       
   357     private:        // New methods
       
   358 
       
   359         /**
       
   360          *  Checks if the given address is valid
       
   361          *
       
   362          *  @param aAddress Address to be checked
       
   363          *  @return Valid address or not
       
   364          */
       
   365         TBool IsValidAddress( const TDesC8& aAddress ) const;   
       
   366         
       
   367         /**
       
   368          *  Checks if the given address is valid
       
   369          *
       
   370          *  @param aAddr Address to be checked
       
   371          *  @return Valid address or not
       
   372          */             
       
   373         TBool IsValidAddress( const TInetAddr& addr ) const;
       
   374 
       
   375         /**
       
   376          *  Checks that address type matches with address format
       
   377          *
       
   378          *  @param aAddress Address
       
   379          *  @param aType Address type
       
   380          *  @param aPool String pool
       
   381          *  @return Type Matches with format or not
       
   382          */
       
   383         TBool TypeMatchesWithFormat( 
       
   384             const TDesC8& aAddress, const TDesC8& aType, 
       
   385             RStringPool aPool ) const;
       
   386 
       
   387         /**
       
   388          *  Checks if the given username is valid
       
   389          *
       
   390          *  @param aUserName Username
       
   391          *  @return Validity of the given username
       
   392          */
       
   393         TBool IsValidUserName( const TDesC8& aUserName ) const;
       
   394 
       
   395         /**
       
   396          *  Parses username, initializes iUserName
       
   397          *
       
   398          *  @param aArray Array containing all the elements
       
   399          */
       
   400         void ParseUserNameL( RArray<TPtrC8>& aArray );
       
   401 
       
   402         /**
       
   403          *  Parses session ID and version, initializes iSessionId
       
   404          *  and iSessionVersion
       
   405          *
       
   406          *  @param aArray Array containing all the elements
       
   407          */
       
   408         void ParseSessionIDAndVersionL( RArray<TPtrC8>& aArray );
       
   409 
       
   410         /**
       
   411          *  Parses network type and address type, initializes
       
   412          *  iNetType and iAddressType
       
   413          *
       
   414          *  @param aArray Array containing all the elements
       
   415          */
       
   416        void ParseNetTypeAndAddressTypeL( RArray<TPtrC8>& aArray );
       
   417 
       
   418         /**
       
   419          *  Parses address, checks address against address type,
       
   420          *  initializes iAddress
       
   421          *
       
   422          *  @param aArray Array containing all the elements
       
   423          */
       
   424         void ParseAddressL( RArray<TPtrC8>& aArray );
       
   425 
       
   426 		inline CSdpOriginFieldPtrs& OriginFieldPtrs();
       
   427 
       
   428 		inline const CSdpOriginFieldPtrs& OriginFieldPtrs() const;
       
   429 
       
   430 		TInt64 Get63Msbs( const TDesC8& aDecimalValue ) const;
       
   431 		void SetIPAddressType( const TInetAddr& aAddr );
       
   432 
       
   433     private:    // Data
       
   434 
       
   435         RStringPool iPool;
       
   436 
       
   437         // <username>
       
   438 		HBufC8* iUserName;
       
   439         // <session id>
       
   440 		TInt64 iSessionId;
       
   441         // <version>
       
   442 		TInt64 iSessionVersion;
       
   443         // <net type>
       
   444         RStringF iNetType;
       
   445         // <address type>        
       
   446         RStringF iAddressType;
       
   447         // <address>
       
   448         // Either one is used (this or iAddressType/iAddress combo)
       
   449         // Can be defined as mutable because this variable does not affect
       
   450         // to the state of the object, but it is needed as const pointer
       
   451         // is returned on InetAddr() method
       
   452 		mutable TInetAddr iUnicastAddress;        
       
   453         TBuf8<KMaxAddressLength> iAddress; 
       
   454         // For configuring the address into TInetAddr
       
   455         TBuf<KMaxAddressLength> iAddress16;          
       
   456 
       
   457 		void __DbgTestInvariant() const;
       
   458 
       
   459 	};
       
   460 
       
   461 #endif // CSDPORIGINFIELD_H