epoc32/include/sdpconnectionfield.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * Name          : SdpConnectionField.h
    16 * Part of       : SDP Codec
    17 * Interface     : SDK API, SDP Codec API
    18 * Version       : 1.0
    19 *
    20 */
    21 
    22 
    23 
    24 #ifndef CSDPCONNECTIONFIELD_H
    25 #define CSDPCONNECTIONFIELD_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 TUint KDefaultNumOfAddress = 1;
    35 
    36 // FORWARD DECLARATIONS
    37 class RReadStream;
    38 class RWriteStream;
    39 
    40 // CLASS DECLARATION
    41 /**
    42  *  @publishedAll
    43  *  @released
    44  *
    45  *	This class encapsulates the connection information 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 CSdpConnectionField : public CBase
    56 	{
    57     public: // Constructors and destructor
    58 
    59         /**
    60          *	Constructs a new connection 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 CSdpConnectionField* DecodeL( const TDesC8& aText );
    67 
    68         /**
    69          *	Constructs a new connection field and adds the pointer to the 
    70          *  cleanup 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 CSdpConnectionField* DecodeLC( const TDesC8& aText );
    77 
    78         /**
    79          *	Constructs a new connection field.
    80 		 *	Also sets the network type to "IN" and address type to "IP4" or
    81 		 *  "IP6" depending on the address family of aAddress.
    82 		 *	
    83 		 *	@param aAddress IP address from either KAfInet 
    84          *         or KAfInet6 family
    85          *  @param aTTL Time-To-Live for IP4 multicasts, set it as
    86          *         KErrNotFound if IPv6 multicast or IPv4 unicast
    87          *  @param aNumOfAddress Number of addresses in multicast,
    88          *         if unicast, must be 1
    89          *	@return a new instance.
    90          */
    91 		IMPORT_C static CSdpConnectionField* NewL(            
    92             const TInetAddr& aAddress,
    93             TInt aTTL = KErrNotFound, 
    94             TUint aNumOfAddress = KDefaultNumOfAddress );
    95 
    96         /**
    97          *	Constructs a new connection field.
    98 		 *	
    99          *	@param aNetType A valid network type name from the pre-
   100          *              defined SDP string table or defined by the user.
   101 		 *  @paramaAddressType A valid address type name from the 
   102          *              pre-defined SDP string table or defined by the user.
   103 		 *	@param  const TDesC8& aAddress: A valid address of the address type.
   104          *              Can contain TTL & number of addresses parameter as well.
   105          *	@return a new instance.
   106          */
   107 		IMPORT_C static CSdpConnectionField* NewL(
   108 			RStringF aNetType, 
   109 			RStringF aAddressType, 
   110 			const TDesC8& aAddress );
   111 
   112 		/**
   113          *	Constructs a new connection field and adds the pointer to the 
   114          *  cleanup stack. Also sets the network type to "IN" and address type
   115 		 *	to "IP4" or "IP6" depending on the address family of aAddress.
   116 		 *
   117 		 *	@param aAddress IP address from either KAfInet 
   118          *              or KAfInet6 family
   119          *  @param aTTL Time-To-Live for IP4 multicasts, set it as
   120          *              KErrNotFound if IPv6 multicast or IPv4 unicast
   121          *  @param aNumOfAddress Number of addresses in multicast,
   122          *              if unicast, must be 1
   123          *	@return a new instance.
   124          */
   125 		IMPORT_C static CSdpConnectionField* NewLC(       
   126             const TInetAddr& aAddress, 
   127             TInt aTTL = KErrNotFound,
   128             TUint aNumOfAddress = KDefaultNumOfAddress );
   129 
   130         /**
   131          *	Construct a new connection field  and adds the pointer to the
   132          *  cleanup stack.
   133 		 *	
   134          *	@param aNetType A valid network type name from the pre-
   135          *         defined SDP string table or defined by the user
   136 		 *  @paramaAddressType A valid address type name from the 
   137          *              pre-defined SDP string table or defined by the user
   138 		 *	@param  const TDesC8& aAddress: A valid address of the address type.
   139          *              Can contain TTL & number of addresses parameter as well.
   140          *	@return a new instance.
   141          */
   142 		IMPORT_C static CSdpConnectionField* NewLC(
   143             RStringF aNetType, RStringF aAddressType, const TDesC8& aAddress );
   144 
   145 		/**
   146 		 *	Deletes the resources held by the instance.
   147 		 */
   148 		IMPORT_C ~CSdpConnectionField();
   149 
   150     public: // New functions
   151 
   152 		/**
   153 		 *	Outputs the field formatted according to SDP syntax and including
   154 		 *  the terminating CRLF.
   155 		 * 
   156 		 *	@param aStream: Stream used for output. On return the
   157          *         stream includes correctly formatted connection field.
   158 		 */
   159 		IMPORT_C void EncodeL( RWriteStream& aStream ) const;
   160 
   161 		/**
   162 		 *	Creates a new instance that is equal to the target.
   163 		 *
   164 		 *	@return a new instance.
   165 		 */
   166 		IMPORT_C CSdpConnectionField* CloneL() const;
   167 
   168 		/**	
   169 		 *	Compares this instance to another for equality.
   170 		 *
   171 		 *	@param const CSdpConnectionField& aObj: The instance to compare to.
   172 		 *	@return ETrue if equal, EFalse if not.
   173 		 */
   174 		IMPORT_C TBool operator== ( const CSdpConnectionField& aObj ) const;
   175 
   176 		/**
   177 		 *	Gets the network type that is from the pre-defined SDP string table
   178          *  or given by the user.
   179 		 *
   180 		 *	@return The network type.
   181 		 */
   182 		IMPORT_C RStringF NetType() const;
   183 
   184 		/**
   185 		 *	Gets the address type that is from the pre-defined SDP string table 
   186          *  or given by the user.
   187 		 *
   188 		 *	@return The address type.
   189 		 */
   190 		IMPORT_C RStringF AddressType() const;
   191 
   192 		/**
   193 		 *	Gets the address.
   194 		 *
   195 		 *	@return Address as an IP address or null if it is
   196          *          not an IP address. This may be e.g. when the address
   197 		 *          has been specified as a FQDN. In this case, the address
   198          *          can be accessed using the other getters.
   199 		 */
   200 		IMPORT_C const TInetAddr* InetAddress() const;
   201 
   202 		/**
   203 		 *	Gets the address.
   204 		 *
   205 		 *  @return Address as a string.
   206 		 */
   207 		IMPORT_C const TDesC8& Address() const;
   208 
   209 		/**
   210 		 *	Sets the address, network and address type. Also sets the network 
   211 		 *	type to "IN" and address type to "IP4" or "IP6" depending on the 
   212 		 *  address family of aAddress.
   213 		 *
   214 		 *	@param aValue The new address.
   215          *  @param aTTL Time-To-Live for IP4 multicasts, set it as
   216          *         KErrNotFound if IPv6 multicast or IPv4 unicast
   217          *  @param aNumOfAddress Number of addresses in multicast,
   218          *         if unicast, must be 1.
   219          *  @leave KErrSdpCodecConnectionField ifaddress to be set is wrongly 
   220          *         formatted.
   221          */
   222 		IMPORT_C void SetInetAddressL( const TInetAddr& aValue, 
   223                                    TInt aTTL = KErrNotFound,
   224                                    TUint aNumOfAddress = KDefaultNumOfAddress);
   225 
   226 		/**
   227 		 *	Sets the address, network and address type.
   228 		 *
   229          *	@param aNetType A valid network type name from the pre-
   230          *         defined SDP string table or defined by the user
   231 		 *  @param aAddressType A valid address type name from the 
   232          *         pre-defined SDP string table or defined by the user
   233 		 *	@param aAddress A valid address of the address type.
   234 		 */
   235 		IMPORT_C void SetAddressL( RStringF aNetType, 
   236 								   RStringF aAddressType, 
   237 								   const TDesC8& aAddress );
   238 
   239         /**
   240          *  Gets TTL attribute.
   241          *
   242          *  @return TTL or KErrNotFound, if one is not available for the address
   243          */
   244         IMPORT_C TInt TTLValue() const;
   245 
   246         /**
   247          *  Sets TTL attribute (only valid for IP4 multicasts).
   248          *  Leaves if trying to set TTL to address that doesn't support it.
   249          *
   250          *  @param aTTL Time-To-Live for IP4 multicasts
   251          *	@leave KErrSdpCodecConnectionField if aTTL is invalid.
   252          */
   253         IMPORT_C void SetTTLL( TInt aTTL );
   254 
   255         /**
   256          *  Gets the number of addresses (can be more than 1 for multicasts).
   257          *  Multicast addresses are contiguously allocated above the base 
   258          *  address.
   259          *
   260          *  @return Number of addresses
   261          */
   262         IMPORT_C TInt NumOfAddress() const;
   263          
   264         /**
   265          *  Sets the number of addreses allocated for multicast. 
   266          *  
   267          *	@param aNumOfAddress Number of addresses in multicast
   268          *  @leave KErrSdpCodecConnectionField if the address is unicast.
   269          */
   270         IMPORT_C void SetNumOfAddressL( TUint aNumOfAddress );
   271 
   272     public:     // Internal to codec
   273 
   274         /**
   275          *  Externalizes the object to stream
   276          *
   277          *  @param aStream Stream where the object's state will be stored
   278          */
   279 		void ExternalizeL( RWriteStream& aStream ) const;
   280 
   281         /**
   282          *  Creates object from the stream data
   283          *
   284          *  @param aStream Stream where the object's state will be read
   285          *  @return Initialized object
   286          */
   287 		static CSdpConnectionField* InternalizeL( RReadStream& aStream );
   288 
   289     private:    // Internal
   290 
   291         /**
   292          *  Constructor
   293          */
   294         CSdpConnectionField();
   295 
   296         /**
   297          *  2nd phase constructor
   298          *
   299          *	@param aText A string containing a correctly formatted field value
   300 		 *         terminated by a CRLF.         
   301          */         
   302         void ConstructL( const TDesC8& aText );
   303         
   304         /**
   305          *  2nd phase constructor
   306          *
   307          *	@param aAddress IP address from either KAfInet or KAfInet6 family
   308          *  @param aTTL Time-To-Live for IP4 multicasts
   309          *  @param aNumOfAddress Nubmer of addresses in multicast
   310          */
   311         void ConstructL( const TInetAddr& aAddress,
   312                          TInt aTTL, TUint aNumOfAddress );
   313 
   314         /**
   315          *  2nd phase constructor
   316          *
   317          *	@param aNetType A valid network type name from the pre-defined
   318 		 *         SDP string table or defined by the user
   319 		 *  @param aAddressType A valid address type name from the pre-defined
   320 		 *         SDP string table or defined by the user
   321 		 *	@param aAddress A valid address of the address type
   322          */
   323         void ConstructL( RStringF aNetType, RStringF aAddressType, 
   324 	                     const TDesC8& aAddress );
   325 
   326         /**
   327          *  Checks if the address is valid against given arguments
   328          *
   329          *  @param aAddressTypeIP4 The given type of address (EFalse = IP6)
   330          *  @param aAddress Address with possibly TTL & number of addresses
   331          *  @return error code (KErrNone if valid)
   332          */
   333         TInt IsValidAddress( TBool aAddressTypeIP4,
   334                              const TDesC8& aAddress ) const;
   335 
   336         /**
   337          *  Checks if the address is valid against given arguments
   338          *         
   339          *  @param aAddress Address in TInetAddr format
   340          *  @param aTTL TTL attribute
   341          *  @param aNumOfAddress Number off addresses
   342          *  @return error code (KErrNone if valid)
   343          */
   344         TInt IsValidAddress( const TInetAddr& aAddress, 
   345                              TInt aTTL, TUint aNumOfAddress ) const;
   346         
   347         /**
   348          *  Parses address field
   349          *
   350          *  @param aAddressTypeIP4 The given type of address (EFalse = IP6)
   351          *  @param aAddress Address with possibly TTL & number of addresses
   352          *  @param aTTL TTL value is stored here (or KErrNotFound)
   353          *  @param aNumberOfAddresses Range of addreses
   354          *  @return The address
   355          */
   356         HBufC8* ParseAddressFieldL( TBool aAddressTypeIP4,
   357                                     const TDesC8& aAddress,
   358                                     TInt& aTTL,
   359                                     TUint& aNumberOfAddresses ) const;
   360 
   361         /**
   362          *  Parses IP4 address
   363          *
   364          *  @param aPos Position of the (first) separation mark         
   365          *  @param aTTL TTL value is stored here (or KErrNotFound)
   366          *  @param aAddr Addres in TInetAddr format
   367          *  @param aAddress The whole address field
   368          *  @param aNumberOfAddresses Range of addreses
   369          *  @return The address
   370          */
   371         HBufC8* ParseIP4AddressL( TInt aPos, 
   372                                   TInetAddr& aAddr,
   373                                   const TDesC8& aAddress,
   374                                   TInt& aTTL,
   375                                   TUint& aNumberOfAddresses ) const;
   376 
   377         /**
   378          *  Parses IP6 address
   379          *
   380          *  @param aPos Position of the (first) separation mark         
   381          *  @param aTTL TTL value is stored here (or KErrNotFound)
   382          *  @param aAddr Addres in TInetAddr format
   383          *  @param aAddress The whole address field
   384          *  @param aNumberOfAddresses Range of addreses
   385          *  @return The address
   386          */
   387         HBufC8* ParseIP6AddressL( TInt aPos, 
   388                                   TInetAddr& aAddr,
   389                                   const TDesC8& aAddress,
   390                                   TInt& aTTL,
   391                                   TUint& aNumberOfAddresses ) const;
   392 
   393         /**
   394          *  Copies given network type to iNetType and verifies aNetType to
   395          *  be valid
   396          *
   397          *  @param aNetType Given network type                
   398          */
   399         void CopyNetTypeL( const TDesC8& aNetType );
   400 
   401         /**
   402          *  Copies given address type to iAddressType and verifies aAddrType
   403          *  to be valid
   404          * 
   405          *  @param aAddrType Given address type     
   406          */
   407         void CopyAddressTypeL( const TDesC8& aAddrType );
   408 
   409         /**
   410          *  Copies address to iAddress, and initalizes TTL & number of addresses,
   411          *  leaves on error
   412          *  
   413          *  @param aAddress Address string, which can also contain TTL
   414          *                  and number of addresses attributes
   415          */
   416         void CopyAddressL( const TDesC8& aAddress, RStringPool aPool );
   417 
   418     private:    // Data
   419 
   420         // <network type>
   421         RStringF iNetType;
   422         
   423         // <address type>        
   424         RStringF iAddressType;
   425 
   426         // mutable TInetAddr for InetAddress()
   427         mutable TInetAddr iInetAddress;
   428 
   429         // Address in text format
   430         HBufC8* iAddress;
   431 
   432         // TTL for IP4 multicast addresses
   433         TInt iTTL;
   434         // Number of addresses
   435         TUint iNumOfAddress;
   436 
   437         // String pool
   438         RStringPool iPool;
   439 
   440         __DECLARE_TEST;
   441 	};
   442 
   443 #endif // CSDPCONNECTIONFIELD_H