1.1 --- a/epoc32/include/sdporiginfield.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/sdporiginfield.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,460 @@
1.4 -sdporiginfield.h
1.5 +/*
1.6 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.7 +* All rights reserved.
1.8 +* This component and the accompanying materials are made available
1.9 +* 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
1.10 +* which accompanies this distribution, and is available
1.11 +* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.12 +*
1.13 +* Initial Contributors:
1.14 +* Nokia Corporation - initial contribution.
1.15 +*
1.16 +* Contributors:
1.17 +*
1.18 +* Description:
1.19 +* Name : SdpOriginField.h
1.20 +* Part of : SDP Codec
1.21 +* Interface : SDK API, SDP Codec API
1.22 +* Version : 1.0
1.23 +*
1.24 +*/
1.25 +
1.26 +
1.27 +
1.28 +#ifndef CSDPORIGINFIELD_H
1.29 +#define CSDPORIGINFIELD_H
1.30 +
1.31 +// INCLUDES
1.32 +#include <e32base.h>
1.33 +#include <in_sock.h>
1.34 +#include <stringpool.h>
1.35 +#include "_sdpdefs.h"
1.36 +
1.37 +// CONSTANTS
1.38 +const TInt KMaxAddressLength = 256;
1.39 +
1.40 +// FORWARD DECLARATIONS
1.41 +class RReadStream;
1.42 +class RWriteStream;
1.43 +class CSdpOriginFieldPtrs;
1.44 +
1.45 +// CLASS DECLARATION
1.46 +/**
1.47 + * @publishedAll
1.48 + * @released
1.49 + *
1.50 + * This class encapsulates the origin field of
1.51 + * the Session Description Protocol.
1.52 + *
1.53 + * The normative reference for correct formatting and values is
1.54 + * draft-ietf-mmusic-sdp-new-14 unless specified otherwise in
1.55 + * member documentation. The implementation supports this normative
1.56 + * reference, but does not enforce it fully.
1.57 + *
1.58 + * @lib sdpcodec.lib
1.59 + */
1.60 +class CSdpOriginField : public CBase
1.61 + {
1.62 + public: // Constructors and destructor
1.63 +
1.64 + /**
1.65 + * Constructs a new origin field.
1.66 + *
1.67 + * @param aText A string containing a correctly
1.68 + * formatted field value terminated by a CRLF.
1.69 + * @return a new instance.
1.70 + */
1.71 + IMPORT_C static CSdpOriginField* DecodeL( const TDesC8& aText );
1.72 +
1.73 + /**
1.74 + * Constructs a new origin field and adds the pointer to the cleanup
1.75 + * stack.
1.76 + *
1.77 + * @param aText A string containing a correctly
1.78 + * formatted field value terminated by a CRLF.
1.79 + * @return a new instance.
1.80 + */
1.81 + IMPORT_C static CSdpOriginField* DecodeLC( const TDesC8& aText );
1.82 +
1.83 + /**
1.84 + * Constructs a new origin field.
1.85 + *
1.86 + * @param aUserName A valid user name value.
1.87 + * @param aSessionId A valid session id value.
1.88 + * @param aSessionVersion A valid announcement version value.
1.89 + * @param aAddress A unicast IP address from either
1.90 + * KAfInet or KAfInet6 family.
1.91 + * @return a new instance.
1.92 + */
1.93 + IMPORT_C static CSdpOriginField* NewL( const TDesC8& aUserName,
1.94 + TInt64 aSessionId,
1.95 + TInt64 aSessionVersion,
1.96 + TInetAddr& aAddress );
1.97 +
1.98 + /**
1.99 + * Constructs a new origin field and adds the pointer to the cleanup
1.100 + * stack.
1.101 + *
1.102 + * @param aUserName A valid user name value.
1.103 + * @param aSessionId A valid session id value.
1.104 + * @param aSessionVersion A valid announcement version value.
1.105 + * @param aAddress A unicast IP address from either
1.106 + * KAfInet or KAfInet6 family.
1.107 + * @return a new instance.
1.108 + */
1.109 + IMPORT_C static CSdpOriginField* NewLC( const TDesC8& aUserName,
1.110 + TInt64 aSessionId,
1.111 + TInt64 aSessionVersion,
1.112 + TInetAddr& aAddress );
1.113 +
1.114 + /**
1.115 + * Constructs a new origin field.
1.116 + *
1.117 + * @param aUserName A valid user name value.
1.118 + * @param aSessionId A valid session id value.
1.119 + * @param aSessionVersion A valid announcement version value.
1.120 + * @param aNetType A valid network type value (typically "IN").
1.121 + * @param aAddressType A valid address type value
1.122 + * (typically "IP4" or "IP6").
1.123 + * @param aAddress A unicast IP Address, Fully
1.124 + * Qualified Domain Name (FQDN), or an other type of
1.125 + * address allowed for the address type.
1.126 + * @return a new instance.
1.127 + */
1.128 + IMPORT_C static CSdpOriginField* NewL( const TDesC8& aUserName,
1.129 + TInt64 aSessionId,
1.130 + TInt64 aSessionVersion,
1.131 + RStringF aNetType,
1.132 + RStringF aAddressType,
1.133 + const TDesC8& aAddress );
1.134 +
1.135 + /**
1.136 + * Constructs a new origin field and adds the pointer to the cleanup
1.137 + * stack.
1.138 + *
1.139 + * @param aUserName A valid user name value.
1.140 + * @param aSessionId A valid session id value.
1.141 + * @param aSessionVersion A valid announcement version value.
1.142 + * @param aNetType A valid network type value (typically "IN").
1.143 + * @param aAddressType A valid address type value
1.144 + * (typically "IP4" or "IP6").
1.145 + * @param aAddress A unicast IP Address, Fully Qualified Domain
1.146 + * Name (FQDN), or an other type of address allowed
1.147 + * for the address type.
1.148 + * @return a new instance.
1.149 + */
1.150 + IMPORT_C static CSdpOriginField* NewLC( const TDesC8& aUserName,
1.151 + TInt64 aSessionId,
1.152 + TInt64 aSessionVersion,
1.153 + RStringF aNetType,
1.154 + RStringF aAddressType,
1.155 + const TDesC8& aAddress );
1.156 +
1.157 + /**
1.158 + * Deletes the resources held by the instance.
1.159 + */
1.160 + IMPORT_C ~CSdpOriginField();
1.161 +
1.162 + public: // New functions
1.163 +
1.164 + /**
1.165 + * Outputs the field formatted according to SDP syntax and including
1.166 + * the terminating CRLF.
1.167 + *
1.168 + * @param aStream Stream used for output. On return
1.169 + * the stream includes correctly formatted origin field.
1.170 + */
1.171 + IMPORT_C void EncodeL( RWriteStream& aStream ) const;
1.172 +
1.173 + /**
1.174 + * Creates a new instance that is equal to the target.
1.175 + *
1.176 + * @return a new instance.
1.177 + */
1.178 + IMPORT_C CSdpOriginField* CloneL() const;
1.179 +
1.180 + /**
1.181 + * Compares this instance to another for equality.
1.182 + *
1.183 + * @param aObj The instance to compare to.
1.184 + * @return ETrue if equal, EFalse if not.
1.185 + */
1.186 + IMPORT_C TBool operator == ( const CSdpOriginField& aObj ) const;
1.187 +
1.188 + /**
1.189 + * Gets the user name.
1.190 + *
1.191 + * @return User name.
1.192 + */
1.193 + IMPORT_C const TDesC8& UserName() const;
1.194 +
1.195 + /**
1.196 + * Sets the user name.
1.197 + *
1.198 + * @param aValue A valid user name value.
1.199 + * @leave KErrSdpCodecOriginField if aValue is not a valid user name.
1.200 + */
1.201 + IMPORT_C void SetUserNameL( const TDesC8& aValue );
1.202 +
1.203 + /**
1.204 + * Gets the session id of the origin field.
1.205 + *
1.206 + * @return Session id.
1.207 + */
1.208 + IMPORT_C TInt64 SessionId() const;
1.209 +
1.210 + /**
1.211 + * Sets the session id.
1.212 + *
1.213 + * @param aValue A valid session id value.
1.214 + */
1.215 + IMPORT_C void SetSessionId( TInt64 aValue );
1.216 +
1.217 + /**
1.218 + * Gets the announcement version.
1.219 + *
1.220 + * @return Version.
1.221 + */
1.222 + IMPORT_C TInt64 Version() const;
1.223 +
1.224 + /**
1.225 + * Sets the announcement version..
1.226 + *
1.227 + * @param aValue A valid version value.
1.228 + */
1.229 + IMPORT_C void SetVersion( TInt64 aValue );
1.230 +
1.231 + /**
1.232 + * Gets the network type.
1.233 + *
1.234 + * @return The network type from pre-defined SDP string
1.235 + * table or given by the user.
1.236 + */
1.237 + IMPORT_C RStringF NetType() const;
1.238 +
1.239 + /**
1.240 + * Gets the address type.
1.241 + *
1.242 + * @return The address type from pre-defined SDP string
1.243 + * table or given by the user.
1.244 + */
1.245 + IMPORT_C RStringF AddressType() const;
1.246 +
1.247 + /**
1.248 + * Gets the address.
1.249 + *
1.250 + * @return Address as an IP address or null if it is
1.251 + * not an IP address. This may be e.g. when the address has
1.252 + * been specified as a FQDN. In this case, the address can be
1.253 + * accessed using the other getters.
1.254 + */
1.255 + IMPORT_C const TInetAddr* InetAddress() const;
1.256 +
1.257 + /**
1.258 + * Gets the address.
1.259 + *
1.260 + * @return Address as a string.
1.261 + */
1.262 + IMPORT_C const TDesC8& Address() const;
1.263 +
1.264 + /**
1.265 + * Sets the address, network and address type.
1.266 + * Also sets the network type to "IN" and address type to "IP4" or
1.267 + * "IP6" depending on the address family of aValue.
1.268 + *
1.269 + * @param aValue A unicast IP address from either KAfInet
1.270 + * or KAfInet6 family.
1.271 + */
1.272 + IMPORT_C void SetInetAddress( const TInetAddr& aValue );
1.273 +
1.274 + /**
1.275 + * Sets the address, network and address type.
1.276 + *
1.277 + * @param aAddress A unicast IP Address, Fully Qualified Domain
1.278 + * Name (FQDN), or an other type of address allowed for the
1.279 + * address type.
1.280 + * @param aNetType A valid network type value (typically "IN").
1.281 + * @param aAddressType A valid address type value
1.282 + * (typically "IP4" or "IP6").
1.283 + * @leave KErrSdpCodecOriginField if aNetType or aAddressType are not
1.284 + * valid tokens, or aAddress is invalid, or aAddress type
1.285 + * is not aligned with the address format
1.286 + */
1.287 + IMPORT_C void SetAddressL( const TDesC8& aAddress,
1.288 + RStringF aNetType,
1.289 + RStringF aAddressType );
1.290 +
1.291 + public: // Internal to codec
1.292 +
1.293 + /**
1.294 + * Externalizes the object to stream
1.295 + *
1.296 + * @param aStream Stream where the object's state will be stored
1.297 + */
1.298 + void ExternalizeL( RWriteStream& aStream ) const;
1.299 +
1.300 + /**
1.301 + * Creates object from the stream data
1.302 + *
1.303 + * @param aStream Stream where the object's state will be read
1.304 + * @return Initialized object
1.305 + */
1.306 + static CSdpOriginField* InternalizeL( RReadStream& aStream );
1.307 +
1.308 + private: // Constructors
1.309 +
1.310 + /**
1.311 + * Constructor
1.312 + */
1.313 + CSdpOriginField();
1.314 +
1.315 + /**
1.316 + * Second phase constructor. Parses the text string and initializes
1.317 + * the member variables
1.318 + *
1.319 + * @param aText Line of text that will be parsed (ends on the newline)
1.320 + */
1.321 + void ConstructL( const TDesC8& aText );
1.322 +
1.323 + /**
1.324 + * Second phase constructor. Constructs the object.
1.325 + *
1.326 + * @param aUserName A valid user name value.
1.327 + * @param aSessionId A valid session id value.
1.328 + * @param aSessionVersion A valid announcement version value.
1.329 + * @param aAddress A unicast IP address from either
1.330 + * KAfInet or KAfInet6 family.
1.331 + */
1.332 + void ConstructL( const TDesC8& aUserName,
1.333 + TInt64 aSessionId,
1.334 + TInt64 aSessionVersion,
1.335 + TInetAddr& aUnicastAddress );
1.336 +
1.337 + /**
1.338 + * Second phase constructor. Constructs the object.
1.339 + *
1.340 + * @param aUserName A valid user name value.
1.341 + * @param aSessionId A valid session id value.
1.342 + * @param aSessionVersion A valid announcement version value.
1.343 + * @param aNetType A valid network type value (typically "IN").
1.344 + * @param aAddressType A valid address type value
1.345 + * (typically "IP4" or "IP6").
1.346 + * @param aAddress A unicast IP Address, Fully Qualified Domain
1.347 + * Name (FQDN), or an other type of address allowed
1.348 + * for the address type.
1.349 + */
1.350 + void ConstructL( const TDesC8& aUserName,
1.351 + TInt64 aSessionId,
1.352 + TInt64 aSessionVersion,
1.353 + RStringF aNetType,
1.354 + RStringF aAddressType,
1.355 + const TDesC8& aAddress );
1.356 +
1.357 + // These are unnecessary? Derived from CBase, prevents the use
1.358 + CSdpOriginField( const CSdpOriginField& ); // Hidden.
1.359 + CSdpOriginField& operator = ( const CSdpOriginField& ); // Hidden
1.360 +
1.361 + private: // New methods
1.362 +
1.363 + /**
1.364 + * Checks if the given address is valid
1.365 + *
1.366 + * @param aAddress Address to be checked
1.367 + * @return Valid address or not
1.368 + */
1.369 + TBool IsValidAddress( const TDesC8& aAddress ) const;
1.370 +
1.371 + /**
1.372 + * Checks if the given address is valid
1.373 + *
1.374 + * @param aAddr Address to be checked
1.375 + * @return Valid address or not
1.376 + */
1.377 + TBool IsValidAddress( const TInetAddr& addr ) const;
1.378 +
1.379 + /**
1.380 + * Checks that address type matches with address format
1.381 + *
1.382 + * @param aAddress Address
1.383 + * @param aType Address type
1.384 + * @param aPool String pool
1.385 + * @return Type Matches with format or not
1.386 + */
1.387 + TBool TypeMatchesWithFormat(
1.388 + const TDesC8& aAddress, const TDesC8& aType,
1.389 + RStringPool aPool ) const;
1.390 +
1.391 + /**
1.392 + * Checks if the given username is valid
1.393 + *
1.394 + * @param aUserName Username
1.395 + * @return Validity of the given username
1.396 + */
1.397 + TBool IsValidUserName( const TDesC8& aUserName ) const;
1.398 +
1.399 + /**
1.400 + * Parses username, initializes iUserName
1.401 + *
1.402 + * @param aArray Array containing all the elements
1.403 + */
1.404 + void ParseUserNameL( RArray<TPtrC8>& aArray );
1.405 +
1.406 + /**
1.407 + * Parses session ID and version, initializes iSessionId
1.408 + * and iSessionVersion
1.409 + *
1.410 + * @param aArray Array containing all the elements
1.411 + */
1.412 + void ParseSessionIDAndVersionL( RArray<TPtrC8>& aArray );
1.413 +
1.414 + /**
1.415 + * Parses network type and address type, initializes
1.416 + * iNetType and iAddressType
1.417 + *
1.418 + * @param aArray Array containing all the elements
1.419 + */
1.420 + void ParseNetTypeAndAddressTypeL( RArray<TPtrC8>& aArray );
1.421 +
1.422 + /**
1.423 + * Parses address, checks address against address type,
1.424 + * initializes iAddress
1.425 + *
1.426 + * @param aArray Array containing all the elements
1.427 + */
1.428 + void ParseAddressL( RArray<TPtrC8>& aArray );
1.429 +
1.430 + inline CSdpOriginFieldPtrs& OriginFieldPtrs();
1.431 +
1.432 + inline const CSdpOriginFieldPtrs& OriginFieldPtrs() const;
1.433 +
1.434 + TInt64 Get63Msbs( const TDesC8& aDecimalValue ) const;
1.435 + void SetIPAddressType( const TInetAddr& aAddr );
1.436 +
1.437 + private: // Data
1.438 +
1.439 + RStringPool iPool;
1.440 +
1.441 + // <username>
1.442 + HBufC8* iUserName;
1.443 + // <session id>
1.444 + TInt64 iSessionId;
1.445 + // <version>
1.446 + TInt64 iSessionVersion;
1.447 + // <net type>
1.448 + RStringF iNetType;
1.449 + // <address type>
1.450 + RStringF iAddressType;
1.451 + // <address>
1.452 + // Either one is used (this or iAddressType/iAddress combo)
1.453 + // Can be defined as mutable because this variable does not affect
1.454 + // to the state of the object, but it is needed as const pointer
1.455 + // is returned on InetAddr() method
1.456 + mutable TInetAddr iUnicastAddress;
1.457 + TBuf8<KMaxAddressLength> iAddress;
1.458 + // For configuring the address into TInetAddr
1.459 + TBuf<KMaxAddressLength> iAddress16;
1.460 +
1.461 + __DECLARE_TEST;
1.462 + };
1.463 +
1.464 +#endif // CSDPORIGINFIELD_H