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