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 : SdpConnectionField.h
17 * Interface : SDK API, SDP Codec API
24 #ifndef CSDPCONNECTIONFIELD_H
25 #define CSDPCONNECTIONFIELD_H
30 #include <stringpool.h>
33 const TUint KDefaultNumOfAddress = 1;
35 // FORWARD DECLARATIONS
44 * This class encapsulates the connection information field of
45 * the Session Description Protocol.
47 * The normative reference for correct formatting and values is
48 * draft-ietf-mmusic-sdp-new-14 unless specified otherwise in
49 * member documentation. The implementation supports this normative
50 * reference, but does not enforce it fully.
54 class CSdpConnectionField : public CBase
56 public: // Constructors and destructor
59 * Constructs a new connection field.
61 * @param aText A string containing a correctly
62 * formatted field value terminated by a CRLF.
63 * @return a new instance.
65 IMPORT_C static CSdpConnectionField* DecodeL( const TDesC8& aText );
68 * Constructs a new connection field and adds the pointer to the
71 * @param aText A string containing a correctly
72 * formatted field value terminated by a CRLF.
73 * @return a new instance.
75 IMPORT_C static CSdpConnectionField* DecodeLC( const TDesC8& aText );
78 * Constructs a new connection field.
79 * Also sets the network type to "IN" and address type to "IP4" or
80 * "IP6" depending on the address family of aAddress.
82 * @param aAddress IP address from either KAfInet
84 * @param aTTL Time-To-Live for IP4 multicasts, set it as
85 * KErrNotFound if IPv6 multicast or IPv4 unicast
86 * @param aNumOfAddress Number of addresses in multicast,
87 * if unicast, must be 1
88 * @return a new instance.
90 IMPORT_C static CSdpConnectionField* NewL(
91 const TInetAddr& aAddress,
92 TInt aTTL = KErrNotFound,
93 TUint aNumOfAddress = KDefaultNumOfAddress );
96 * Constructs a new connection field.
98 * @param aNetType A valid network type name from the pre-
99 * defined SDP string table or defined by the user.
100 * @paramaAddressType A valid address type name from the
101 * pre-defined SDP string table or defined by the user.
102 * @param const TDesC8& aAddress: A valid address of the address type.
103 * Can contain TTL & number of addresses parameter as well.
104 * @return a new instance.
106 IMPORT_C static CSdpConnectionField* NewL(
108 RStringF aAddressType,
109 const TDesC8& aAddress );
112 * Constructs a new connection field and adds the pointer to the
113 * cleanup stack. Also sets the network type to "IN" and address type
114 * to "IP4" or "IP6" depending on the address family of aAddress.
116 * @param aAddress IP address from either KAfInet
118 * @param aTTL Time-To-Live for IP4 multicasts, set it as
119 * KErrNotFound if IPv6 multicast or IPv4 unicast
120 * @param aNumOfAddress Number of addresses in multicast,
121 * if unicast, must be 1
122 * @return a new instance.
124 IMPORT_C static CSdpConnectionField* NewLC(
125 const TInetAddr& aAddress,
126 TInt aTTL = KErrNotFound,
127 TUint aNumOfAddress = KDefaultNumOfAddress );
130 * Construct a new connection field and adds the pointer to the
133 * @param aNetType A valid network type name from the pre-
134 * defined SDP string table or defined by the user
135 * @paramaAddressType A valid address type name from the
136 * pre-defined SDP string table or defined by the user
137 * @param const TDesC8& aAddress: A valid address of the address type.
138 * Can contain TTL & number of addresses parameter as well.
139 * @return a new instance.
141 IMPORT_C static CSdpConnectionField* NewLC(
142 RStringF aNetType, RStringF aAddressType, const TDesC8& aAddress );
145 * Deletes the resources held by the instance.
147 IMPORT_C ~CSdpConnectionField();
149 public: // New functions
152 * Outputs the field formatted according to SDP syntax and including
153 * the terminating CRLF.
155 * @param aStream: Stream used for output. On return the
156 * stream includes correctly formatted connection field.
158 IMPORT_C void EncodeL( RWriteStream& aStream ) const;
161 * Creates a new instance that is equal to the target.
163 * @return a new instance.
165 IMPORT_C CSdpConnectionField* CloneL() const;
168 * Compares this instance to another for equality.
170 * @param const CSdpConnectionField& aObj: The instance to compare to.
171 * @return ETrue if equal, EFalse if not.
173 IMPORT_C TBool operator== ( const CSdpConnectionField& aObj ) const;
176 * Gets the network type that is from the pre-defined SDP string table
177 * or given by the user.
179 * @return The network type.
181 IMPORT_C RStringF NetType() const;
184 * Gets the address type that is from the pre-defined SDP string table
185 * or given by the user.
187 * @return The address type.
189 IMPORT_C RStringF AddressType() const;
194 * @return Address as an IP address or null if it is
195 * not an IP address. This may be e.g. when the address
196 * has been specified as a FQDN. In this case, the address
197 * can be accessed using the other getters.
199 IMPORT_C const TInetAddr* InetAddress() const;
204 * @return Address as a string.
206 IMPORT_C const TDesC8& Address() const;
209 * Sets the address, network and address type. Also sets the network
210 * type to "IN" and address type to "IP4" or "IP6" depending on the
211 * address family of aAddress.
213 * @param aValue The new address.
214 * @param aTTL Time-To-Live for IP4 multicasts, set it as
215 * KErrNotFound if IPv6 multicast or IPv4 unicast
216 * @param aNumOfAddress Number of addresses in multicast,
217 * if unicast, must be 1.
218 * @leave KErrSdpCodecConnectionField ifaddress to be set is wrongly
221 IMPORT_C void SetInetAddressL( const TInetAddr& aValue,
222 TInt aTTL = KErrNotFound,
223 TUint aNumOfAddress = KDefaultNumOfAddress);
226 * Sets the address, network and address type.
228 * @param aNetType A valid network type name from the pre-
229 * defined SDP string table or defined by the user
230 * @param aAddressType A valid address type name from the
231 * pre-defined SDP string table or defined by the user
232 * @param aAddress A valid address of the address type.
234 IMPORT_C void SetAddressL( RStringF aNetType,
235 RStringF aAddressType,
236 const TDesC8& aAddress );
239 * Gets TTL attribute.
241 * @return TTL or KErrNotFound, if one is not available for the address
243 IMPORT_C TInt TTLValue() const;
246 * Sets TTL attribute (only valid for IP4 multicasts).
247 * Leaves if trying to set TTL to address that doesn't support it.
249 * @param aTTL Time-To-Live for IP4 multicasts
250 * @leave KErrSdpCodecConnectionField if aTTL is invalid.
252 IMPORT_C void SetTTLL( TInt aTTL );
255 * Gets the number of addresses (can be more than 1 for multicasts).
256 * Multicast addresses are contiguously allocated above the base
259 * @return Number of addresses
261 IMPORT_C TInt NumOfAddress() const;
264 * Sets the number of addreses allocated for multicast.
266 * @param aNumOfAddress Number of addresses in multicast
267 * @leave KErrSdpCodecConnectionField if the address is unicast.
269 IMPORT_C void SetNumOfAddressL( TUint aNumOfAddress );
271 public: // Internal to codec
274 * Externalizes the object to stream
276 * @param aStream Stream where the object's state will be stored
278 void ExternalizeL( RWriteStream& aStream ) const;
281 * Creates object from the stream data
283 * @param aStream Stream where the object's state will be read
284 * @return Initialized object
286 static CSdpConnectionField* InternalizeL( RReadStream& aStream );
293 CSdpConnectionField();
296 * 2nd phase constructor
298 * @param aText A string containing a correctly formatted field value
299 * terminated by a CRLF.
301 void ConstructL( const TDesC8& aText );
304 * 2nd phase constructor
306 * @param aAddress IP address from either KAfInet or KAfInet6 family
307 * @param aTTL Time-To-Live for IP4 multicasts
308 * @param aNumOfAddress Nubmer of addresses in multicast
310 void ConstructL( const TInetAddr& aAddress,
311 TInt aTTL, TUint aNumOfAddress );
314 * 2nd phase constructor
316 * @param aNetType A valid network type name from the pre-defined
317 * SDP string table or defined by the user
318 * @param aAddressType A valid address type name from the pre-defined
319 * SDP string table or defined by the user
320 * @param aAddress A valid address of the address type
322 void ConstructL( RStringF aNetType, RStringF aAddressType,
323 const TDesC8& aAddress );
326 * Checks if the address is valid against given arguments
328 * @param aAddressTypeIP4 The given type of address (EFalse = IP6)
329 * @param aAddress Address with possibly TTL & number of addresses
330 * @return error code (KErrNone if valid)
332 TInt IsValidAddress( TBool aAddressTypeIP4,
333 const TDesC8& aAddress ) const;
336 * Checks if the address is valid against given arguments
338 * @param aAddress Address in TInetAddr format
339 * @param aTTL TTL attribute
340 * @param aNumOfAddress Number off addresses
341 * @return error code (KErrNone if valid)
343 TInt IsValidAddress( const TInetAddr& aAddress,
344 TInt aTTL, TUint aNumOfAddress ) const;
347 * Parses address field
349 * @param aAddressTypeIP4 The given type of address (EFalse = IP6)
350 * @param aAddress Address with possibly TTL & number of addresses
351 * @param aTTL TTL value is stored here (or KErrNotFound)
352 * @param aNumberOfAddresses Range of addreses
353 * @return The address
355 HBufC8* ParseAddressFieldL( TBool aAddressTypeIP4,
356 const TDesC8& aAddress,
358 TUint& aNumberOfAddresses ) const;
363 * @param aPos Position of the (first) separation mark
364 * @param aTTL TTL value is stored here (or KErrNotFound)
365 * @param aAddr Addres in TInetAddr format
366 * @param aAddress The whole address field
367 * @param aNumberOfAddresses Range of addreses
368 * @return The address
370 HBufC8* ParseIP4AddressL( TInt aPos,
372 const TDesC8& aAddress,
374 TUint& aNumberOfAddresses ) const;
379 * @param aPos Position of the (first) separation mark
380 * @param aTTL TTL value is stored here (or KErrNotFound)
381 * @param aAddr Addres in TInetAddr format
382 * @param aAddress The whole address field
383 * @param aNumberOfAddresses Range of addreses
384 * @return The address
386 HBufC8* ParseIP6AddressL( TInt aPos,
388 const TDesC8& aAddress,
390 TUint& aNumberOfAddresses ) const;
393 * Copies given network type to iNetType and verifies aNetType to
396 * @param aNetType Given network type
398 void CopyNetTypeL( const TDesC8& aNetType );
401 * Copies given address type to iAddressType and verifies aAddrType
404 * @param aAddrType Given address type
406 void CopyAddressTypeL( const TDesC8& aAddrType );
409 * Copies address to iAddress, and initalizes TTL & number of addresses,
412 * @param aAddress Address string, which can also contain TTL
413 * and number of addresses attributes
415 void CopyAddressL( const TDesC8& aAddress, RStringPool aPool );
423 RStringF iAddressType;
425 // mutable TInetAddr for InetAddress()
426 mutable TInetAddr iInetAddress;
428 // Address in text format
431 // TTL for IP4 multicast addresses
433 // Number of addresses
439 void __DbgTestInvariant() const;
444 #endif // CSDPCONNECTIONFIELD_H