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