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