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