2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Name : SdpOriginField.h
17 * Interface : SDK API, SDP Codec API
24 #ifndef CSDPORIGINFIELD_H
25 #define CSDPORIGINFIELD_H
30 #include <stringpool.h>
33 const TInt KMaxAddressLength = 256;
35 // FORWARD DECLARATIONS
38 class CSdpOriginFieldPtrs;
45 * This class encapsulates the origin field of
46 * the Session Description Protocol.
48 * The normative reference for correct formatting and values is
49 * draft-ietf-mmusic-sdp-new-14 unless specified otherwise in
50 * member documentation. The implementation supports this normative
51 * reference, but does not enforce it fully.
55 class CSdpOriginField : public CBase
57 public: // Constructors and destructor
60 * Constructs a new origin field.
62 * @param aText A string containing a correctly
63 * formatted field value terminated by a CRLF.
64 * @return a new instance.
66 IMPORT_C static CSdpOriginField* DecodeL( const TDesC8& aText );
69 * Constructs a new origin field and adds the pointer to the cleanup
72 * @param aText A string containing a correctly
73 * formatted field value terminated by a CRLF.
74 * @return a new instance.
76 IMPORT_C static CSdpOriginField* DecodeLC( const TDesC8& aText );
79 * Constructs a new origin field.
81 * @param aUserName A valid user name value.
82 * @param aSessionId A valid session id value.
83 * @param aSessionVersion A valid announcement version value.
84 * @param aAddress A unicast IP address from either
85 * KAfInet or KAfInet6 family.
86 * @return a new instance.
88 IMPORT_C static CSdpOriginField* NewL( const TDesC8& aUserName,
90 TInt64 aSessionVersion,
91 TInetAddr& aAddress );
94 * Constructs a new origin field and adds the pointer to the cleanup
97 * @param aUserName A valid user name value.
98 * @param aSessionId A valid session id value.
99 * @param aSessionVersion A valid announcement version value.
100 * @param aAddress A unicast IP address from either
101 * KAfInet or KAfInet6 family.
102 * @return a new instance.
104 IMPORT_C static CSdpOriginField* NewLC( const TDesC8& aUserName,
106 TInt64 aSessionVersion,
107 TInetAddr& aAddress );
110 * Constructs a new origin field.
112 * @param aUserName A valid user name value.
113 * @param aSessionId A valid session id value.
114 * @param aSessionVersion A valid announcement version value.
115 * @param aNetType A valid network type value (typically "IN").
116 * @param aAddressType A valid address type value
117 * (typically "IP4" or "IP6").
118 * @param aAddress A unicast IP Address, Fully
119 * Qualified Domain Name (FQDN), or an other type of
120 * address allowed for the address type.
121 * @return a new instance.
123 IMPORT_C static CSdpOriginField* NewL( const TDesC8& aUserName,
125 TInt64 aSessionVersion,
127 RStringF aAddressType,
128 const TDesC8& aAddress );
131 * Constructs a new origin field and adds the pointer to the cleanup
134 * @param aUserName A valid user name value.
135 * @param aSessionId A valid session id value.
136 * @param aSessionVersion A valid announcement version value.
137 * @param aNetType A valid network type value (typically "IN").
138 * @param aAddressType A valid address type value
139 * (typically "IP4" or "IP6").
140 * @param aAddress A unicast IP Address, Fully Qualified Domain
141 * Name (FQDN), or an other type of address allowed
142 * for the address type.
143 * @return a new instance.
145 IMPORT_C static CSdpOriginField* NewLC( const TDesC8& aUserName,
147 TInt64 aSessionVersion,
149 RStringF aAddressType,
150 const TDesC8& aAddress );
153 * Deletes the resources held by the instance.
155 IMPORT_C ~CSdpOriginField();
157 public: // New functions
160 * Outputs the field formatted according to SDP syntax and including
161 * the terminating CRLF.
163 * @param aStream Stream used for output. On return
164 * the stream includes correctly formatted origin field.
166 IMPORT_C void EncodeL( RWriteStream& aStream ) const;
169 * Creates a new instance that is equal to the target.
171 * @return a new instance.
173 IMPORT_C CSdpOriginField* CloneL() const;
176 * Compares this instance to another for equality.
178 * @param aObj The instance to compare to.
179 * @return ETrue if equal, EFalse if not.
181 IMPORT_C TBool operator == ( const CSdpOriginField& aObj ) const;
184 * Gets the user name.
188 IMPORT_C const TDesC8& UserName() const;
191 * Sets the user name.
193 * @param aValue A valid user name value.
194 * @leave KErrSdpCodecOriginField if aValue is not a valid user name.
196 IMPORT_C void SetUserNameL( const TDesC8& aValue );
199 * Gets the session id of the origin field.
201 * @return Session id.
203 IMPORT_C TInt64 SessionId() const;
206 * Sets the session id.
208 * @param aValue A valid session id value.
210 IMPORT_C void SetSessionId( TInt64 aValue );
213 * Gets the announcement version.
217 IMPORT_C TInt64 Version() const;
220 * Sets the announcement version..
222 * @param aValue A valid version value.
224 IMPORT_C void SetVersion( TInt64 aValue );
227 * Gets the network type.
229 * @return The network type from pre-defined SDP string
230 * table or given by the user.
232 IMPORT_C RStringF NetType() const;
235 * Gets the address type.
237 * @return The address type from pre-defined SDP string
238 * table or given by the user.
240 IMPORT_C RStringF AddressType() const;
245 * @return Address as an IP address or null if it is
246 * not an IP address. This may be e.g. when the address has
247 * been specified as a FQDN. In this case, the address can be
248 * accessed using the other getters.
250 IMPORT_C const TInetAddr* InetAddress() const;
255 * @return Address as a string.
257 IMPORT_C const TDesC8& Address() const;
260 * Sets the address, network and address type.
261 * Also sets the network type to "IN" and address type to "IP4" or
262 * "IP6" depending on the address family of aValue.
264 * @param aValue A unicast IP address from either KAfInet
265 * or KAfInet6 family.
267 IMPORT_C void SetInetAddress( const TInetAddr& aValue );
270 * Sets the address, network and address type.
272 * @param aAddress A unicast IP Address, Fully Qualified Domain
273 * Name (FQDN), or an other type of address allowed for the
275 * @param aNetType A valid network type value (typically "IN").
276 * @param aAddressType A valid address type value
277 * (typically "IP4" or "IP6").
278 * @leave KErrSdpCodecOriginField if aNetType or aAddressType are not
279 * valid tokens, or aAddress is invalid, or aAddress type
280 * is not aligned with the address format
282 IMPORT_C void SetAddressL( const TDesC8& aAddress,
284 RStringF aAddressType );
286 public: // Internal to codec
289 * Externalizes the object to stream
291 * @param aStream Stream where the object's state will be stored
293 void ExternalizeL( RWriteStream& aStream ) const;
296 * Creates object from the stream data
298 * @param aStream Stream where the object's state will be read
299 * @return Initialized object
301 static CSdpOriginField* InternalizeL( RReadStream& aStream );
303 private: // Constructors
311 * Second phase constructor. Parses the text string and initializes
312 * the member variables
314 * @param aText Line of text that will be parsed (ends on the newline)
316 void ConstructL( const TDesC8& aText );
319 * Second phase constructor. Constructs the object.
321 * @param aUserName A valid user name value.
322 * @param aSessionId A valid session id value.
323 * @param aSessionVersion A valid announcement version value.
324 * @param aAddress A unicast IP address from either
325 * KAfInet or KAfInet6 family.
327 void ConstructL( const TDesC8& aUserName,
329 TInt64 aSessionVersion,
330 TInetAddr& aUnicastAddress );
333 * Second phase constructor. Constructs the object.
335 * @param aUserName A valid user name value.
336 * @param aSessionId A valid session id value.
337 * @param aSessionVersion A valid announcement version value.
338 * @param aNetType A valid network type value (typically "IN").
339 * @param aAddressType A valid address type value
340 * (typically "IP4" or "IP6").
341 * @param aAddress A unicast IP Address, Fully Qualified Domain
342 * Name (FQDN), or an other type of address allowed
343 * for the address type.
345 void ConstructL( const TDesC8& aUserName,
347 TInt64 aSessionVersion,
349 RStringF aAddressType,
350 const TDesC8& aAddress );
352 // These are unnecessary? Derived from CBase, prevents the use
353 CSdpOriginField( const CSdpOriginField& ); // Hidden.
354 CSdpOriginField& operator = ( const CSdpOriginField& ); // Hidden
356 private: // New methods
359 * Checks if the given address is valid
361 * @param aAddress Address to be checked
362 * @return Valid address or not
364 TBool IsValidAddress( const TDesC8& aAddress ) const;
367 * Checks if the given address is valid
369 * @param aAddr Address to be checked
370 * @return Valid address or not
372 TBool IsValidAddress( const TInetAddr& addr ) const;
375 * Checks that address type matches with address format
377 * @param aAddress Address
378 * @param aType Address type
379 * @param aPool String pool
380 * @return Type Matches with format or not
382 TBool TypeMatchesWithFormat(
383 const TDesC8& aAddress, const TDesC8& aType,
384 RStringPool aPool ) const;
387 * Checks if the given username is valid
389 * @param aUserName Username
390 * @return Validity of the given username
392 TBool IsValidUserName( const TDesC8& aUserName ) const;
395 * Parses username, initializes iUserName
397 * @param aArray Array containing all the elements
399 void ParseUserNameL( RArray<TPtrC8>& aArray );
402 * Parses session ID and version, initializes iSessionId
403 * and iSessionVersion
405 * @param aArray Array containing all the elements
407 void ParseSessionIDAndVersionL( RArray<TPtrC8>& aArray );
410 * Parses network type and address type, initializes
411 * iNetType and iAddressType
413 * @param aArray Array containing all the elements
415 void ParseNetTypeAndAddressTypeL( RArray<TPtrC8>& aArray );
418 * Parses address, checks address against address type,
419 * initializes iAddress
421 * @param aArray Array containing all the elements
423 void ParseAddressL( RArray<TPtrC8>& aArray );
425 inline CSdpOriginFieldPtrs& OriginFieldPtrs();
427 inline const CSdpOriginFieldPtrs& OriginFieldPtrs() const;
429 TInt64 Get63Msbs( const TDesC8& aDecimalValue ) const;
430 void SetIPAddressType( const TInetAddr& aAddr );
441 TInt64 iSessionVersion;
445 RStringF iAddressType;
447 // Either one is used (this or iAddressType/iAddress combo)
448 // Can be defined as mutable because this variable does not affect
449 // to the state of the object, but it is needed as const pointer
450 // is returned on InetAddr() method
451 mutable TInetAddr iUnicastAddress;
452 TBuf8<KMaxAddressLength> iAddress;
453 // For configuring the address into TInetAddr
454 TBuf<KMaxAddressLength> iAddress16;
456 void __DbgTestInvariant() const;
460 #endif // CSDPORIGINFIELD_H