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